使用CamelTestSupport的Junit 5

时间:2018-01-17 03:00:03

标签: spring-boot junit5

我正在尝试使用JUnit 5和Camel支持编写单元测试。

  1. JUnit 5(5.0.0)在A类中使用以下注释@方法级别:
  2. @Test
    @ParameterizedTest(name = "Test case [{index}] name={3}")
    @MethodSource("data")
    @IfEnvProfile(profiles = {"preprod"}) (Customized Annotation)
    
    1. A类扩展使用Junit的CamelTestSupport 4.使用以下代码点击服务:
    2. protected ResponseDto  getReponse(String testFile) throws Exception {
          Transaction tx= new Transaction ();
          final Map<String,Object> headers= setAllHeader(tx);
          // enter code here
          ResponseDto response =
              (RatingResponseDto) template.sendBodyAndHeaders("{{.location.enricher.uri}}",
                  ExchangePattern.InOut, tx, headers);
      }
      

      其中location.enricher.uri - http://localhost/rating-service/api/v1/rate/d155446421121/location/(正在运行)。

      但是当我运行它时,我总是在响应时收到Nullpointer异常。

      疑惑:

      1. 是否可以将A类中的JUnit 5和扩展为A类的CamelSupport中的JUnit 4组合在一起?

      2. 我们对JUnit 5有CamelTestSupportClass吗?

      3. 有人可以帮忙吗?

        谢谢, Rajesh S

2 个答案:

答案 0 :(得分:4)

  1. 否:类org.apache.camel.test.junit4.CamelTestSupport仅适用于JUnit 4。
  2. 否:Camel还没有对JUnit Jupiter(即JUnit 5)的支持,但他们有一个open issue来在以后的版本中添加这样的支持。

答案 1 :(得分:1)

当前Camel支持Junit5。您只需将其包含在pom.xml中

yourMethod(event: any) {
  const controlName = e.target.getAttribute('formcontrolname');
  this.formGroup.get(controlName); // this is your FormControl
  ....
}

并导入类:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-test-junit5</artifactId>
</dependency>

有关更多信息,请参见here