Skip to content

Commit 2b39718

Browse files
committed
Add JUnit 6 example
1 parent 488b9f0 commit 2b39718

10 files changed

Lines changed: 223 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ jobs:
2525
- name: Checkout repository
2626
uses: actions/checkout@v4
2727

28-
- name: Set up JDK 11
28+
- name: Set up JDK 17
2929
uses: actions/setup-java@v4
3030
with:
3131
distribution: 'temurin'
32-
java-version: '11'
32+
java-version: '17'
3333

3434
- name: Compile with Maven
3535
run: mvn -B test-compile

example-junit5/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<dependency>
2222
<groupId>com.epam.reportportal</groupId>
2323
<artifactId>agent-java-junit5</artifactId>
24-
<version>5.5.4</version>
24+
<version>5.5.7</version>
2525
</dependency>
2626

2727
<dependency>
@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>ch.qos.logback</groupId>
4646
<artifactId>logback-classic</artifactId>
47-
<version>1.5.18</version>
47+
<version>1.5.32</version>
4848
</dependency>
4949

5050
<dependency>

example-junit6/pom.xml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2026 EPAM Systems
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<parent>
21+
<artifactId>examples-java</artifactId>
22+
<groupId>com.epam.reportportal</groupId>
23+
<version>1.0-SNAPSHOT</version>
24+
</parent>
25+
<modelVersion>4.0.0</modelVersion>
26+
27+
<groupId>com.epam.reportportal.example</groupId>
28+
<artifactId>example-junit6</artifactId>
29+
30+
<properties>
31+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32+
<maven.compiler.release>17</maven.compiler.release>
33+
</properties>
34+
35+
<dependencyManagement>
36+
<dependencies>
37+
<dependency>
38+
<groupId>org.junit</groupId>
39+
<artifactId>junit-bom</artifactId>
40+
<version>6.0.3</version>
41+
<type>pom</type>
42+
<scope>import</scope>
43+
</dependency>
44+
</dependencies>
45+
</dependencyManagement>
46+
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.junit.jupiter</groupId>
50+
<artifactId>junit-jupiter</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>com.epam.reportportal</groupId>
56+
<artifactId>agent-java-junit5</artifactId>
57+
<version>5.5.7</version>
58+
<scope>test</scope>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>com.epam.reportportal</groupId>
63+
<artifactId>logger-java-logback</artifactId>
64+
<version>5.4.0</version>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>ch.qos.logback</groupId>
69+
<artifactId>logback-classic</artifactId>
70+
<version>1.5.32</version>
71+
<scope>test</scope>
72+
</dependency>
73+
</dependencies>
74+
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<artifactId>maven-surefire-plugin</artifactId>
79+
<version>3.5.4</version>
80+
</plugin>
81+
</plugins>
82+
</build>
83+
84+
</project>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.epam.reportportal.example.junit6;
2+
3+
import com.epam.reportportal.annotations.TestCaseId;
4+
import com.epam.reportportal.annotations.TestCaseIdKey;
5+
import org.junit.jupiter.api.DynamicTest;
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.TestFactory;
8+
import org.junit.jupiter.params.ParameterizedTest;
9+
import org.junit.jupiter.params.provider.ValueSource;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
13+
import java.util.stream.Stream;
14+
15+
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
16+
17+
public class TestCaseIdTest {
18+
19+
private static final Logger LOGGER = LoggerFactory.getLogger(TestCaseIdTest.class);
20+
21+
@Test
22+
void testCaseIdFromCodeRefTest() {
23+
LOGGER.info("Test case id should be generated from code reference");
24+
}
25+
26+
@ParameterizedTest
27+
@ValueSource(ints = { 101, 0, 1 })
28+
void testCaseIdFromCodeRefAndParamsTest(int parameter) {
29+
LOGGER.info("Test case id should be generated from code reference and parameters");
30+
LOGGER.info("Parameter {}", parameter);
31+
}
32+
33+
@TestCaseId("test-case-id")
34+
@Test
35+
void testCaseIdFromAnnotationValueTest() {
36+
LOGGER.info("Test case id should be provided from annotation value");
37+
}
38+
39+
@TestCaseId(parametrized = true)
40+
@ParameterizedTest
41+
@ValueSource(strings = { "one", "two" })
42+
void testCaseIdFromParametrizedAnnotationTest(@TestCaseIdKey String parameter) {
43+
LOGGER.info("Test case id should be generated from parameter value marked @TestCaseIdKey annotation");
44+
LOGGER.info("Parameter {}", parameter);
45+
}
46+
47+
@TestCaseId(parametrized = true)
48+
@ParameterizedTest
49+
@ValueSource(chars = { 't', 'e', 's', 't' })
50+
void testCaseIdFromParametrizedAnnotationTest(@TestCaseIdKey char parameter) {
51+
LOGGER.info("Test case id should be generated from parameter value marked @TestCaseIdKey annotation");
52+
LOGGER.info("Parameter {}", parameter);
53+
}
54+
55+
@TestFactory
56+
Stream<DynamicTest> dynamicTests() {
57+
return Stream.of(dynamicTest("testCaseIdFromDynamicTest",
58+
() -> LOGGER.info("Test case id should be generated from code reference")
59+
));
60+
}
61+
62+
@TestCaseId("test-case-id-dynamic")
63+
@TestFactory
64+
Stream<DynamicTest> dynamicAnnotatedTests() {
65+
return Stream.of(dynamicTest("testCaseIdFromDynamicTest",
66+
() -> LOGGER.info("Test case id should be generated from annotation value")
67+
));
68+
}
69+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<aspectj>
2+
<aspects>
3+
<aspect name="com.epam.reportportal.aspect.StepAspect"/>
4+
</aspects>
5+
</aspectj>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.epam.reportportal.junit5.ReportPortalExtension
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
junit.jupiter.extensions.autodetection.enabled=true
2+
junit.jupiter.execution.parallel.enabled=true
3+
junit.jupiter.execution.parallel.config.strategy=dynamic
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2024 EPAM Systems
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<configuration>
19+
20+
<!-- Send debug messages to System.out -->
21+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
22+
<!-- By default, encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
23+
<encoder>
24+
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{5} - %thread - %msg%n</pattern>
25+
</encoder>
26+
</appender>
27+
28+
<appender name="RP" class="com.epam.reportportal.logback.appender.ReportPortalAppender">
29+
<encoder>
30+
<!--Best practice: don't put time and logging level to the final message. Appender do this for you-->
31+
<pattern>%d{HH:mm:ss.SSS} [%t] %-5level - %msg%n</pattern>
32+
<pattern>[%t] - %msg%n</pattern>
33+
</encoder>
34+
</appender>
35+
36+
<!-- We turned off framework logging by setting root level="WARN" to avoid logging encoded data into console. By setting level="TRACE"
37+
for "binary_data_logger" and connected it only to RP appender to log that data to ReportPortal. The 'additivity' flag is important!
38+
Without it logback will double-log log messages -->
39+
<logger name="binary_data_logger" level="TRACE" additivity="false">
40+
<appender-ref ref="RP"/>
41+
</logger>
42+
<logger name="com.epam.reportportal.example" level="TRACE"/>
43+
44+
<!-- By default, the level of the root level is set to DEBUG -->
45+
<root level="WARN">
46+
<appender-ref ref="RP"/>
47+
<appender-ref ref="STDOUT"/>
48+
</root>
49+
50+
</configuration>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rp.endpoint=https://example.com
2+
rp.api.key=api-key
3+
rp.launch=JUnit 6
4+
rp.project=project-name
5+
rp.attributes=key:value;value

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<maven.compiler.encoding>${project.build.sourceEncoding}</maven.compiler.encoding>
1515
<maven.resources.encoding>${project.build.sourceEncoding}</maven.resources.encoding>
16-
<maven.compiler.source>11</maven.compiler.source>
16+
<maven.compiler.source>17</maven.compiler.source>
1717
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
1818
</properties>
1919

@@ -25,6 +25,7 @@
2525
<module>example-jbehave</module>
2626
<module>example-junit</module>
2727
<module>example-junit5</module>
28+
<module>example-junit6</module>
2829
<module>example-karate</module>
2930
<module>example-spock</module>
3031
<module>example-testng-fork-execution</module>

0 commit comments

Comments
 (0)