Concept: AUnit Tests
AUnit is a Workday Studio test framework that enables you to develop and run unit tests for assemblies. You can develop AUnit tests in Java using test skeletons that you create in your assembly projects. AUnit test skeletons support these features:
- Actions
- Annotations
- Assertions
You can use these features to build test cases for your assemblies.
Example:
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); } }
Annotations
All AUnit tests must contain an
@AssemblyTest
annotation. This annotation identifies your AUnit test and enables you to associate the test with your assembly project. Example:
@AssemblyTest(project = "AUnitTrainer")
Annotations on test methods define the starting point for a unit test in the assembly processing chain. Example:
@UnitTest(startComponent = "Simple-Mediation")
Assertions
Assertions define Boolean test conditions. If an assertion fails, AUnit aborts the assembly execution and displays the test result as a failure. If an unexpected exception occurs, AUnit aborts the assembly execution and displays the test result as an error.
Example: The sample below uses an
@AssertAfter
annotation and an assertTrue
assertion to check whether the root message part contains the expected XML after the mediation executes.
@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)); }
Actions
Actions define AUnit test behaviors when the assembly execution reaches a component or exit point. Example:
@AtComponent(id="Next-Thing") public Action handleAfterMediation() throws Exception { return new StandardAction(Action.Type.terminate); }