VSTS中Maven构建未执行JUnit测试及报告发布失败求助
Update: Root cause identified! Read on for matching solutions
Hey there! I’ve tackled identical issues with VSTS (now Azure DevOps) and Maven Surefire in the past, so let’s break down what’s likely going on and how to fix it based on your scenario:
Common Root Causes & Fixes
1. CI Profile Skipping Tests
Check if your pom.xml includes a CI-specific profile that skips tests. Teams often add this to speed up builds, but it can accidentally disable test execution:
<profile> <id>ci</id> <properties> <maven.test.skip>true</maven.test.skip> </properties> </profile>
Verify your VSTS Maven task isn’t passing -P ci or similar flags, and ensure no pipeline variables are setting maven.test.skip to true.
2. Surefire Plugin Configuration Gap
Even if local runs work, VSTS might be using a default Surefire setup that misses your test classes. Explicitly define the plugin in your pom.xml to enforce consistency:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.20.1</version> <configuration> <includes> <include>**/*Test.java</include> </includes> </configuration> </plugin> </plugins> </build>
This guarantees Surefire picks up your ContactTest.java every time, regardless of the environment.
3. Incorrect Working Directory in VSTS
VSTS sometimes uses a different working directory than your local machine, causing Maven to miss your test classes. In your Maven task, confirm the Working directory points directly to the folder containing your pom.xml (in this case, source/module).
4. JDK Version Mismatch
If VSTS uses a different JDK version than your local Eclipse/Windows setup, it can break test compilation or execution. Match the JDK version in your VSTS build agent to what you use locally (check the JDK version dropdown in the Maven task settings).
5. Test Report Path Misconfiguration
Even if tests run, VSTS will fail to publish results if it can’t find the JUnit XML reports (generated by Surefire in target/surefire-reports/). Fix this by:
- Setting the "Publish Test Results" task to target
**/target/surefire-reports/*.xml - Ensuring your Maven task doesn’t clean the
targetdirectory before publishing tests
Since you mentioned you’ve found the root cause, it’s almost certainly one of these scenarios! For example, if your VSTS task was accidentally triggering a test-skipping profile, removing that flag would immediately bring back the JUnit output and resolve the publish failure.
内容的提问来源于stack exchange,提问作者JDG

