GitHub CI 使用 Maven 测试没有 运行 任何测试
GitHub CI with maven testing not running any tests
我绝对是 CI 和 GitHub 的新手,尤其是两者的组合。
我有一个小组项目,我们使用 maven 进行构建,使用 junit 5 进行测试的 maven surefire。我们有几个测试 运行 在本地很好,但是我们的 maven.yml 没有配置 repo 没有 运行 这些测试。这是 .yml 的当前迭代(所有当前注释的行都是我们测试过的):
name: Java CI with Maven
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
#run: mvn -B package --file pom.xml
run: mvn --batch-mode --update-snapshots verify
- run: npm ci
- run: npm run build --if-present
- run: npm test
#- name: Test with Maven
#run: mvn -Dtest="test/*Test" test
#run: mvn '-Dtest=test.*Test' test
这是我们目前的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>Izsakazsivany</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>maven-unit-test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
使用这个和来自 Intellij 的 maven 集成的默认“测试”生命周期,我们所有的测试都是 运行 本地的。 (据我所知,intellij maven 测试生命周期使用以下行进行测试:
test -f pom.xml
)。然而,当我们使用我们的 CI 配置在 GitHub 上尝试此操作时,它说在默认测试中没有找到测试:
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ Izsakazsivany ---
[INFO] No tests to run.
(旁注:izsakazsivany 是我们的项目名称
旁注2:上面两行之间大约有100行下载)
是什么导致了本地版本和 GitHub 上的版本之间的这种差异,为什么当相同的 mvn 命令是 运行 时却看不到测试?
编辑:这可能是一个重要的规范,我们的测试在一个名为 test 的包中,在特定包中用于单独的 类 被测试。
示例:git/src/main/test/entity
问题终于解决了,问题出在错误的项目结构上,我们需要在 pom.xml 中添加一行,详细说明在哪里可以找到测试。
<testSourceDirectory>src/main/test/java/com/team</testSourceDirectory>
编辑:这个问题很可能与糟糕的项目结构有关,因为我们的测试文件夹太深了。通过扩展,这也意味着我们的包名称也必须重做。建议:确保您的项目结构在一开始就正确,以避免出现此类问题。
我绝对是 CI 和 GitHub 的新手,尤其是两者的组合。 我有一个小组项目,我们使用 maven 进行构建,使用 junit 5 进行测试的 maven surefire。我们有几个测试 运行 在本地很好,但是我们的 maven.yml 没有配置 repo 没有 运行 这些测试。这是 .yml 的当前迭代(所有当前注释的行都是我们测试过的):
name: Java CI with Maven
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
#run: mvn -B package --file pom.xml
run: mvn --batch-mode --update-snapshots verify
- run: npm ci
- run: npm run build --if-present
- run: npm test
#- name: Test with Maven
#run: mvn -Dtest="test/*Test" test
#run: mvn '-Dtest=test.*Test' test
这是我们目前的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>Izsakazsivany</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>maven-unit-test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
使用这个和来自 Intellij 的 maven 集成的默认“测试”生命周期,我们所有的测试都是 运行 本地的。 (据我所知,intellij maven 测试生命周期使用以下行进行测试:
test -f pom.xml
)。然而,当我们使用我们的 CI 配置在 GitHub 上尝试此操作时,它说在默认测试中没有找到测试:
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ Izsakazsivany ---
[INFO] No tests to run.
(旁注:izsakazsivany 是我们的项目名称 旁注2:上面两行之间大约有100行下载)
是什么导致了本地版本和 GitHub 上的版本之间的这种差异,为什么当相同的 mvn 命令是 运行 时却看不到测试?
编辑:这可能是一个重要的规范,我们的测试在一个名为 test 的包中,在特定包中用于单独的 类 被测试。
示例:git/src/main/test/entity
问题终于解决了,问题出在错误的项目结构上,我们需要在 pom.xml 中添加一行,详细说明在哪里可以找到测试。
<testSourceDirectory>src/main/test/java/com/team</testSourceDirectory>
编辑:这个问题很可能与糟糕的项目结构有关,因为我们的测试文件夹太深了。通过扩展,这也意味着我们的包名称也必须重做。建议:确保您的项目结构在一开始就正确,以避免出现此类问题。