メインコンテンツにスキップ
Administrator Guide
最終更新: 2023-06-23
概念: AUnit テスト

概念: 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); }