Integration tests not getting executed - java

I have some junit tests and htmlunit integration tests in one of my maven project. The problem is that my integration tests are not getting executed when I run
mvn clean test
Junit Tests Here:
webstore\src\test\java\com\istore\dao\AddressTest.java
Integration Tests Here:
webstore\src\test\java\com\istore\presentation\htmlunit\PageTests.java
How does mvn determines that AddressTest.java should execute and other one should not?

http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#includes describes the expected filepatterns.
btw, if you are talking about integration tests, have a look at the maven-failsafe-plugin. It uses *IT.java as file pattern

The problem is suffix Tests, should be Test in your PageTests.java!
By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:
**/Test*.java - includes all of its subdirectories and all java filenames that start with Test.
**/*Test.java - includes all of its subdirectories and all java filenames that end with Test.
**/*TestCase.java - includes all of its subdirectories and all java filenames that end with TestCase.
Maven Failsafe Plugin is for integration tests and uses suffix IT. To invoke integration tests with Failsafe Plugin use
mvn verify
References:
Inclusions and Exclusions of Tests in Surefire
Inclusions and Exclusions of Tests in Failsafe

Problem resolved after executing following command:
mvn failsafe:integration-test

Related

Spring #Autowire does not find beans through `mvn verify`

I have a Spring (not Spring Boot) project at https://github.com/poggs/spring-autowire-it-problem.
When running the integration test ExampleComponentIT through IntelliJ IDEA, both tests pass and the code can find the bean ExampleComponent. When running the integration test with mvn verify, it fails as it can't find ExampleComponent.
What I want is for mvn verify to be able to find ExampleComponent as it's executed as part of the CI build process.
Can anyone point out where I'm going wrong?
Peter, I have fixed this problem by a temporal workaround
mvn verify -Dfailsafe.useModulePath=false
The fix is already done and it will be released in the version 3.0.0-M6. There the workaround useModulePath=false would not be needed anymore.
It does not make sense to name it an integration test, e.g. ExampleComponentIT, if you want to load the classes from target/classes.
The version 3.0.0-M5 is right, and you should properly build or guarantee that the JAR file works as expected and then maven-failsafe-plugin would work properly with the integration tests.
The difference between Surefire and Failsafe is that Failsafe may fail on verify but the Surefire fails on test phase. Additionally, the Failsafe plugin uses JAR file instead of target/classes which is what the integration test expect due to the package phase happens before the phases integration-test and verify.
When running maven-surefire-plugin, specifically 3.0.0-M5, through mvn clean verify, the directory target/classes is not on the classpath. This directory contains the compiled Java code needed by the integration test.
Adding the following to the maven-failsafe-plugin configuration in pom.xml fixes the problem:
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>target/classes</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
Alternatively, downgrading to 3.0.0-M4 works.

Jenkins pipeline - Separating unit tests and integration test results

I'm using JenkinsFile to manage our pipeline.
Since, we integrated maven-failsafe-plugin to run the unit tests and integration tests separately, we get separate result reports from both plugins.
This is how i configured the same in JenkinsFile in the post section:
junit testResults: '**/target/surefire-reports/*.xml, **/target/failsafe-reports/*.xml'
I would have expected Jenkins to show unit tests and integration tests separately, but unfortunately, Jenkins merges the results of both XML and there is no clear distinction between unit test and integration tests.
We want our builds to have a separate view on Integration tests results.
Is there anyway to do that with Jenkins?
I dont know a way how to do that in Jenkins itself, but maybe a workaround. After you use mvn clean verify you can use mvn site in a jenkins pipeline and build a HTML representation. These testresults are splitted between failsafe and surefire and you can open it directly from your workspace and look into the diffrent results from failsafe and surefire plugin.

mvn package executes more tests locally that in bamboo

I have a spring-boot application which includes JUnit tests and I build using maven. I have organized by JUnit tests in a Suite using #Suite.SuiteClasses notation.
My problem/question is why when I run mvn package locally, I see that the unit tests referenced by the Suite are executed but they are also executed as if they were not part of the suite, while building the code in Bamboo, using again mvn package executes the tests only once (i.e. as members of the suite).
Do you use the same profiles / settings / maven commands on bamboo and locally?
I think what happens is that when executing the package phase the surefire-plugin starts executing all the tests. There might be a naming issue with the includes the surefire plugin uses by default.
If you execute the maven goal with -X you should be able to see the surefire-plugin configuration it uses to identify the tests. This should only match your suites - not the suites and the tests themselves.

Cucumber tests are being skipped

I am using cucumber framework in my project. So for the reporting part, i need have started building the cucumber reports with jenkins.
So during the setup for the trail build i am facing the below issues.
All the tests are skipped, but not executing.
Can anyone have solution. I am happy to provide any other inputs required.
When using maven and cucumber you have two options to run the tests.
With maven: mvn clean install
With cucumber:-Dtest=Runnerclass test
Where Runnerclass is the class name of runner.
Include surefire plugin in your POM.xml to pick your test. if you want to run test as well, then use mvn clean install.
Refer
How to run Cucumber JVM Test in Jenkins

Which tests are run after hitting 'mvn test'?

Maven project has following folder structure:
src/main/java
src/main/resources
src/test/java
src/test/resources
If we navigate to maven project folder and then hit mvn clean test. This command will clean the project then build the project and run the tests
But, I didn't understand which tests it will run.
In which folder, of above folder structure, it will look for tests to execute? (Maybe src/test/java?)
Based on what, it will determine if particular method is test? (Maybe TestNG or JUnit test methods?)
Maven uses Surefire test plugin by default.
It looks for the unit tests in src/test/java as you correctly guessed in your question.
Surefire supports several unit testing frameworks, such as JUnit and TestNG or POJO tests. So if you have both TestNG and JUnit tests in src/test/java and have appropriate test dependencies for both frameworks in your pom.xml both JUnit and TestNG tests will be executed.

Categories