Tests are OK with mvn test, but fails in mvn package

527 Views Asked by At

We have a JUnit 5 test in a Spring Boot project testing the response from a controller that creates a Protobuf output. If I execute the test suite from within an IDE (both Eclipse and IntelliJ are used in the team) as JUnit tests, all pass. If I run mvn test from a terminal they also pass. BUT, if execute mvn package this test fails.

I can't figure out what the difference is here, the test phase should be the same in testand package? Is this related to how we depend on Jupiter somehow?

When the test fails it will end up with a 406 response instead of the expected 200. This is is the same behavior as when a ProtobufHttpMessageConverter is not registered in the context. This puzzles me though, the test runs perfect in the test phase so why not when package is executed?

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.22.0</version>
  <dependencies>
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-surefire-provider</artifactId>
      <version>1.2.0</version>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>5.2.0</version>
    </dependency>
  </dependencies>
</plugin>
  ...
<dependencies>
  <dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <version>1.2.0</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.2.0</version>
    <scope>test</scope>
  </dependency>
</dependencies>

This is the output when the test fails:

Async:
Async started = false
 Async result = null

Resolved Exception:
         Type = org.springframework.web.HttpMediaTypeNotAcceptableException

 ModelAndView:
     View name = null
          View = null
         Model = null 

 FlashMap:
    Attributes = null

 MockHttpServletResponse:
        Status = 406
 Error message = null
       Headers = {}
  Content type = null
          Body = 
 Forwarded URL = null
Redirected URL = null
       Cookies = []
0

There are 0 best solutions below