Closed freddyouellette closed 1 year ago
Hi, this is currently expected as that's how boot test slices work https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#features.testing.spring-boot-applications.autoconfigured-tests. It's better summarised in this blog post https://josefczech.cz/2020/03/08/3-tips-for-using-spring-boot-test-slices/.
I'm wondering if we should try to make testing of a full app easier, aka shell specific SpringBootTest
which would load everything.
I think having an annotation more similar to @SpringBootTest
could be nice for smaller programs, and for tests that need to run multiple commands. That is the annotation that I would want to use in my use case.
How can I load all Beans (or even just the relevant ones) with @ShellTest
? Because it conflicts and throws errors if @SpringBootTest
is also present.
You need to import configs manually. @SpringBootTest
is not compatible with slice testing in boot nor can even be used with testing shell app unless you specify command line args(which doesn't launch interactive mode).
I'll think about this a little and create a new issue. I do appreciate feedback as that helps to develop things more aligned what users need.
Superseded by #738
This works for me:
@ShellTest
@ComponentScan(basePackages = "base.package.name")
class TestClass {
...
}
I generated a project using Spring Initializr with spring-shell. I'm trying to run Integration Tests, but it seems that the ApplicationContext of the test class is not being loaded correctly.
Below is the simple command I made. If I do not import the
OtherService
, the integration test works fine.The Integration test is as follows:
When I run
mvn verify
, I get the following output:In a different project, I am using
spring-shell
with Embedded PostGres, and it seems that the database@Configuration
files are not being loaded properly either. I have tried a lot of different annotation combinations to no avail. It seems that the@ShellTest
annotation does almost everything that the@SpringBootApplication
annotation does, but it is not fully loading theApplicationContext
. Please let me know if you would like me to provide more context, or information about my other use case with Embedded PostGres.The full code can be found here.