首先在專案裡建立一個名為junit的資料夾放置測試程式碼。根據Component的結構,必須準備六個Class才能作完整的一對一測試;這六個Class我只先準備空的基本建構方法與只執行父類別的initialObject()、disposeObject()。接著建立要對六個Class作測試的TestCase。再來在TestCase裡的setUpBeforeClass()加上建立Properties與Implementation的動作,在tearDownAfterClass()裡對應地消滅它們;至於setUp()與tearDown()則沒有什麼特別要做的。

基本Component的功能是建立起內部六個部分的合作機制,因此測試時只針對Implation、Flow與Action三個部分測試其內部的變數是否建立成功。用以下的程式碼建立起基本Component物件的參數集合與其本身:
// 建立測試用的Properties.
properties = new BasePropertiesAbstractTest();
properties.setProperty(BasePropertiesInterface.CLASS_MODEL,
"tw.idv.joying.comp.BaseModelAbstractTest");
properties.setProperty(BasePropertiesInterface.CLASS_FLOW,
"tw.idv.joying.comp.BaseFlowAbstractTest");
properties.setProperty(BasePropertiesInterface.CLASS_ACTION,
"tw.idv.joying.comp.BaseActionAbstractTest");
// 建立測試用的Implementation Class.
impl = new BaseImplAbstractTest();
impl.setProperties(properties);
impl.initialObject();
再根據每個部分裡所擁有的變數加以測試。經過測試與修改之後,終於讓所有的測試方法都可以得到正確結果:

沒有留言:
張貼留言