Pattern selector

Most relevant patterns first. Most helpful ones displayed. Click here to show all.

  1. NPE when use @SpringBootTest and @WebAppConfiguration
    Spring TestContext Framework
    2
    1
    0

Your stack trace compared to the selected pattern

Jump to solutionsExpand frames
java.lang.NullPointerException
8 matching frames hidden
java.lang.IllegalStateException: Failed to load ApplicationContext
18 matching frames hidden
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
8 frames hidden

Solution

JaviRpo2 months ago

You don't need @WebAppConfiguration with @SpringBootTest support.

So just delete @WebAppConfiguration, and then...

  • if you want a mocked WebApplicationContext -- for example, to use MockMvc -- use @SpringBootTest with the default webEnvironment (which is WebEnvironment.MOCK).
  • if you want your web application to actually be deployed in an embedded Servlet container -- for example, to test with TestRestTemplate -- use @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) or @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)

External results for this pattern (3)

  1. No message found for this stack trace.
    Show stack trace