0

I have several test classes annotated with @RunWith and @ContextConfiguration. I use the following dependencies in my maven SpringBoot project:

<dependency>
  <groupId>org.springframework.batch</groupId>
  <artifactId>spring-batch-test</artifactId>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <scope>test</scope>
</dependency>

and when I run mvn clean verify it executes all my test classes.

Now I have a specific test class that I want to ignore during the verify phase.

I tried to annotate it with @ConditionalOnProperty, so at the end the class is as following:

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = { RestTemplate.class, AvailabilityService.class, VerifyService.class,ConfirmService.class })
@ComponentScan(basePackages = "it.alpitour")
@TestPropertySource("classpath:application-test.properties")
@ConditionalOnProperty("test.api.real.run")
public class ToIgnoreTest {

so I have added a property inside my application-test.properties file:

test.api.real.run=false

but the test is still executed and not ignored, during the verify phase.

How can I skip it?

Thanks

edit:

I prefer not to use @Ignore because I need at some point to run that specific test manually. What I just need is to exclude that one when all the other tests are running.

Briston12
  • 357
  • 3
  • 15
  • Name the tests according to naming schema like unit tests `*Test.java` and integration tests like `*IT.java` ... – khmarbaise Aug 13 '20 at 13:40

1 Answers1

1

You can use the annotation @ignore on your test class if you are using Junit 4 or else you could use the command as follows :

mvn -Dtest=\!YourTest* install

but I think since you are using springboot and not spring the better answer would be : how to run/turn off selective tests based on profiles in spring boot

Ananthapadmanabhan
  • 5,706
  • 6
  • 22
  • 39