Skip to content

Commit

Permalink
Added a sample Maven project to generate junit report xml
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Oct 21, 2024
1 parent c235b0d commit 56d71eb
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sample-maven/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Sample Maven project that can be used to generate junitReport.xml
that has various interesting ingredients.
90 changes: 90 additions & 0 deletions sample-maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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>test</groupId>
<artifactId>sample-maven</artifactId>
<version>1.0-SNAPSHOT</version>

<name>sample-maven</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!-- Optionally: parameterized tests support -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.6.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
10 changes: 10 additions & 0 deletions sample-maven/src/main/java/test/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package test;

/**
* Hello world!
*/
public class App {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
35 changes: 35 additions & 0 deletions sample-maven/src/test/java/test/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package test;

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

/**
* Unit test for simple App.
*/
public class AppTest {

/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue() {
assertTrue(true);
}

@Test
public void failingTest() {
System.err.println("stderr output");
assertTrue(false);
}

@Test
public void errorTest() {
System.out.println("stdout output");
throw new IllegalArgumentException("Some unexpected error");
}

@Disabled
public void ignoredTest() {}
}
11 changes: 11 additions & 0 deletions sample-maven/src/test/java/test/sub/AnotherTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package test.sub;

import org.junit.jupiter.api.Test;

public class AnotherTest {
@Test
public void foo() {}

@Test
public void bar() {}
}

0 comments on commit 56d71eb

Please sign in to comment.