0

I'm coming back to Java world again...

I'm following a tutorial (https://spring.io/guides/gs/spring-boot/) and when I run the tests using mvn test, none of the tests in HelloControllerIT are getting run. It seems that only classes that end with 'Test' are considered. I'm sure there is a way to add additional patterns so that HelloControllerIT is included.

Where can I find more information on this topic?

This seems like a simple thing, so I'm probably not using the right keywords in my search (e.g., 'java spring boot test pattern').

Update

Thanks to Yug Singh's answer, I was able to come up with a solution that I feel good with. I added this to my pom.xml file and now I can run unit tests separate from integration tests.

I forgot about profiles...

+    <profiles>
+        <profile>
+            <id>integration</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <includes>
+                                <include>**/*IT.java</include>
+                            </includes>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>

Run unit tests

mvn test

Run integration tests

mvn test -Pintegration

References (StackOverflow):

David Vezzani
  • 1,449
  • 16
  • 24

1 Answers1

0

You can try out the following in pom.xml file:

<build>
  <testSourceDirectory>src/main/java</testSourceDirectory>
  <plugins>
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <version>2.16</version>
       <configuration>
          <includes>
             <include>**/*.java</include>
          </includes>
       </configuration>
    </plugin>
 </plugins>

IMHO, you should place the tests in test packages only as that is the convention.

Yug Singh
  • 3,112
  • 5
  • 27
  • 52