0

实际上,@Christoph 的所有建议代码都没有给出答案,Christoph 的解释在测试前的场景中是有效的,但在测试后的场景中是无效的

    @Configuration
    public class AppConfig {

    @Bean(name="correlationId")
    public String getCorrelationId() {
        return RandomNumberFunction.getRandomNumber(48, false);
    }

    @Bean
    @DependsOn("correlationId")
    public SequenceAfterTest afterTest() {
        return new KrampCitrusTestRunnerAfterTestSupport();
    }

    @Bean
    @DependsOn("correlationId")
    public SequenceBeforeTest  beforeTest() {
        return new KrampCitrusTestRunnerBeforeTestSupport();
     }
    }

考试课后

    public class KrampCitrusTestRunnerAfterTestSupport
        extends TestRunnerAfterTestSupport {


    @Override
    public void afterTest(TestRunner runner) {

         runner.echo("This action should be executed after each test");
         runner.fail("message");
      }
    }

所以这个配置产生以下结果 - 请注意它的测试成功报告?!?!

14:19:50,900 INFO         citrus.Citrus| 
14:19:50,901 INFO         citrus.Citrus| 
14:19:50,903 WARN       citrus.TestCase| After test failed with errors
com.consol.citrus.exceptions.TestCaseFailedException: Test case failed
    at com.consol.citrus.TestCase.executeAction(TestCase.java:236)
    at com.consol.citrus.dsl.runner.DefaultTestRunner.run(DefaultTestRunner.java:198)
    at com.consol.citrus.dsl.runner.DefaultTestRunner.fail(DefaultTestRunner.java:265)
    at com.kramp.eai.test.common.iibexception.KrampCitrusTestRunnerAfterTestSupport.afterTest(KrampCitrusTestRunnerAfterTestSupport.java:45)
    at com.consol.citrus.dsl.runner.TestRunnerAfterTestSupport.doExecute(TestRunnerAfterTestSupport.java:48)
    at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
    at com.consol.citrus.TestCase.afterTest(TestCase.java:203)....
    Caused by: com.consol.citrus.exceptions.CitrusRuntimeException: message
at com.consol.citrus.actions.FailAction.doExecute(FailAction.java:40)
at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
at com.consol.citrus.TestCase.executeAction(TestCase.java:229)
... 31 more
14:19:50,917 INFO         citrus.Citrus| 
14:19:50,917 INFO         citrus.Citrus| -----------------------------------
 -------------------------------------
14:19:50,917 INFO         citrus.Citrus| 
14:19:50,918 INFO         citrus.Citrus| 
14:19:50,918 INFO         citrus.Citrus| AFTER TEST SUITE: SUCCESS
14:19:50,918 INFO         citrus.Citrus| -----------------------------------
-------------------------------------
14:19:50,918 INFO         citrus.Citrus| 
14:19:50,918 INFO         citrus.Citrus| -----------------------------------
-------------------------------------
14:19:50,918 INFO         citrus.Citrus| 
14:19:50,918 INFO         citrus.Citrus| CITRUS TEST RESULTS
14:19:50,918 INFO         citrus.Citrus| 
14:19:50,924 INFO         citrus.Citrus|  TC12: CDM............................... SUCCESS
14:19:50,924 INFO         citrus.Citrus| 
14:19:50,924 INFO         citrus.Citrus| TOTAL: 1
14:19:50,924 INFO         citrus.Citrus| FAILED:    0 (0.0%)
4

1 回答 1

0

这是因为您处于 JUnit 或 TestNG 的后测试阶段。从技术上讲,这不再是柑橘测试的一部分。您应该在 Citrus 中使用 *AfterTestSupport 类,如下所述:http ://www.citrusframework.org/reference/html/test-suite.html#after-test 。只有这样您才能访问 Citrus 中的测试变量和测试边界。

于 2017-02-27T07:44:51.583 回答