Concept: AUnit-tests
AUnit is een Workday Studio-testframework waarmee u eenheidstests voor merken kunt ontwikkelen en uitvoeren. U kunt AUnit-tests in Java ontwikkelen met behulp van testframeworks die u in uw assemblageprojecten maakt. AUnit-testframeworks ondersteunen de volgende functies:
- Acties
- Annotaties
- Beweringen
U kunt deze functies gebruiken om testcases voor uw merken samen te stellen.
Voorbeeld:
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); } }
Annotaties
Alle AUnit-tests moeten een bevatten
@AssemblyTest
annotatie. Met deze annotatie wordt uw AUnit-test aangegeven en kunt u de test koppelen aan uw assemblageproject. Voorbeeld:
@AssemblyTest(project = "AUnitTrainer")
Annotaties in testmethoden definiëren het beginpunt voor een eenheidstest in de verwerkingsketen van het merk. Voorbeeld:
@UnitTest(startComponent = "Simple-Mediation")
Beweringen
Beweringen definiëren Boole-testvoorwaarden. Als een verklaring mislukt, breekt AUnit de uitvoering van de assemblage af en wordt het testresultaat weergegeven als een fout. Als zich een onverwachte uitzondering voordoet, breekt AUnit de uitvoering van de assemblage af en wordt het testresultaat weergegeven als een fout.
Voorbeeld: in het onderstaande voorbeeld wordt an . gebruikt
@AssertAfter
annotatie en an assertTrue
om te controleren of het hoofdberichtgedeelte de verwachte XML bevat nadat de bemiddeling is uitgevoerd.
@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)); }
Acties
Acties definiëren het AUnit-testgedrag wanneer de uitvoering van de assemblage een component of exitpunt bereikt. Voorbeeld:
@AtComponent(id="Next-Thing") public Action handleAfterMediation() throws Exception { return new StandardAction(Action.Type.terminate); }