Spring boot testing - passing command line arguments

I have an integration test with annotations on it:

@WebAppConfiguration @ActiveProfiles("integration") @ContextConfiguration(loader = SpringApplicationContextLoader, classes = [MyApplication]) @IntegrationTest(["server.port=0"]) 

I can pass, for example, the server.port property to check the context, but is there a way to pass command line arguments? My application starts as usual:

 public static final void main(String[] args) { SpringApplication.run(AnkaraCollectorApplication.class, args); } 

and I want to pass some arguments to check the context. Is there any property for this?

+5
source share
1 answer

If you use maven, you can pass test JVM arguments inside a secure plugin:

<plugin> <artifactId>maven-failsafe-plugin</artifactId> <executions> <execution> ... <configuration>
<argLine> whatever you want: -DhelloWorld=Test </argLine> </configuration> ...

You can also set these JVM arguments based on the maven profile you are running:

<profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <!-- Development JVM arguments --> <test-arguments>-Dhello=true</test-arguments> <!-- Default environment --> <environment>develop</environment> </properties> </profile> ... <plugin> <artifactId>maven-failsafe-plugin</artifactId> <executions> <execution> ... <configuration>
<argLine>${test-arguments}</argLine> </configuration> ...

0
source

Source: https://habr.com/ru/post/1215293/


All Articles