I'm an absolute newbie to CI and GitHub, and especially the combination of the two. I have a group project where we use maven for building, maven surefire with junit 5 for testing. We have a couple of tests that run just fine locally, but no config of our maven.yml the repo doesn't run these tests. Here's the current iteration of the .yml (all the currently commented lines are ones that we tested):
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
and here's our current 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>
Using this and the default "test" lifecycle from Intellij's maven integration, all our tests are ran locally. (The intellij maven test lifecycle uses the following line for testing to my knowledge:
test -f pom.xml
). However when we try this on GitHub using our CI configuration it says that no tests were found in the default test:
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ Izsakazsivany ---
[INFO] No tests to run.
(side note: izsakazsivany is our project name side note2: there are about 100 lines of downloads between the 2 above lines)
What is causing this discrepancy between the local version and the one on GitHub, how come it's not seeing the tests when the same mvn commands are ran?
Edit: This may be an important specification our tests are in a package called test and in specific packages for the separate classes that are tested.
Example: git/src/main/test/entity
Issue is resolved finally, the issue was with a bad project structure and we needed to add a line to pom.xml detailing where the tests can be found.
<testSourceDirectory>src/main/test/java/com/team</testSourceDirectory>
Edit: The issue most likely had to do with bad project structure, as our tests folder was to deep down. By extension this also meant that our package names also had to be redone. Advice: make sure your project structure is correct at the very start to avoid issues like this.