概念:AUnit 测试
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
注释此注释可标识您的 AUnit 测试,并使您能够将该测试与您的程序集项目相关联。示例:
@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); }