So my test class cannot find the beans if I do not mention the application test in the test class annotations
@RunWith(SpringJUnit4ClassRunner::class)
@SpringBootTest(classes=[MySpringApplication::class])
@WebAppConfiguration
class MyFooIT{...}
I've seen (and written) other tests (in other projects and in this) where I did not need to mention the class explicitly.
I'm not sure why this is happening and I'm suspecting not knowing might result in my running into issues later on.
When do you need to provide a class with the @SpringBootTest
annotation, and when don't you?
There are two situations when you may have to specify the application class you want to use in the @SpringBootTest
:
com.example
as root package, and Module B depends on Module A and also use com.example
as root package) You may check if your MyFooIT
is under the hierarchy of the root package (containing MySpringApplication
), or if you have multiple application classes under the same root package.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.