You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSTS中Maven构建未执行JUnit测试及报告发布失败求助

Fix: Maven Tests Not Running in VSTS (No JUnit Output & Publish Test Results Failure)

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 target directory 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:29:50