概念︰A 單元測試
AUnit 是一個 Workday Studio 測試框架,可讓您開發和執行程序集的單元測試。您可以使用在程序集專案中建立的測試主旨,以 Java 開發 AUnit 測試。AUnit 測試框架支援以下功能︰
- 動作
- 註解
- 判斷提示
您可以使用這些功能來建立程序集的測試用例。
範例︰
package com.workday.training.aunit; import java.io.InputStream; import com.workday.aunit.AssemblyTestCase; import com.workday.aunit.actions.Action; import com.workday.aunit.actions.StandardAction; import com.workday.aunit.annotations.AssemblyTest; import com.workday.aunit.annotations.AssertAfter; import com.workday.aunit.annotations.AtComponent; import com.workday.aunit.annotations.UnitTest; @AssemblyTest(project = "AUnitTrainer", displayLabel = "Citizens of the Cloud") public class SimpleMediationTest extends AssemblyTestCase { @UnitTest(startComponent = "Simple-Mediation") public void testSimpleMediation() throws Exception { setMessagePart(0, "test/simple-input.xml", "text/xml"); } // Using the @AssertAfter annotation and the assertTrue assertion. // @AssertAfter(id = "Simple-Mediation", step="transform") public void verifySimpleMediation() throws Exception { assertTrue(compare( getTestResourceInputStream("test/simple-expected.xml"), "text/xml", (InputStream) getMediationContext().getMessage().getMessagePart(0, InputStream.class), "text/xml", Comparator.dom)); } @AtComponent(id="Next-Thing") public Action handleAfterMediation() throws Exception { return new StandardAction(Action.Type.terminate); } }
註解
所有 AUnit 測試都必須包含
@AssemblyTest
註解此註解可識別您的邏輯單元測試,並使您能夠將該測試與您的程序集專案建立關聯。範例︰
@AssemblyTest(project = "AUnitTrainer")
測試方法上的註解定義了程序集處理鏈中單元測試的起點。範例︰
@UnitTest(startComponent = "Simple-Mediation")
判斷提示
判斷提示定義了布林測試條件。如果判斷提示失敗,AUnit 會中止程序集執行,並將測試結果顯示為失敗。如果發生非預期的例外狀況,AUnit 會中止程序集執行,並將測試結果顯示為錯誤。
範例︰以下範例使用
@AssertAfter
註解和 assertTrue
判斷提示,以在中介執行後檢查根訊息部分是否包含預期的 XML。
@AssertAfter(id = "Simple-Mediation", step="transform") public void verifySimpleMediation() throws Exception { assertTrue(compare( getTestResourceInputStream("test/simple-expected.xml"), "text/xml", (InputStream) getMediationContext().getMessage().getMessagePart(0, InputStream.class), "text/xml", Comparator.dom)); }
動作
動作定義了程序集執行至元件或退出點時的 AUnit 測試行為。範例︰
@AtComponent(id="Next-Thing") public Action handleAfterMediation() throws Exception { return new StandardAction(Action.Type.terminate); }