This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JUnit5 support works in the same way as for other xUnit engines. Also, all related documentation is updated. #160
- Loading branch information
Showing
15 changed files
with
443 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
# Artifacts | ||
|
||
Sunshine consists of 3 libraries | ||
Sunshine consists of 4 libraries | ||
- `sunshine-core` provides interfaces and common implementations | ||
- `sunshine-junit4` wraps JUnit4 to allow the creation of [entry points](entry-points.md) | ||
- `sunshine-junit5` wraps JUnit5 to allow the creation of [entry points](entry-points.md) | ||
- `sunshine-testng` wraps TestNG to allow the creation of [entry points](entry-points.md) | ||
|
||
Artifact|`sunshine-testng`|`sunshine-junit4`|`sunshine-core` | ||
---|---|---|--- | ||
Library|[![](https://img.shields.io/maven-central/v/org.tatools/sunshine-testng.svg)](https://search.maven.org/search?q=g:%22org.tatools%22%20AND%20a:%22sunshine-testng%22)|[![](https://img.shields.io/maven-central/v/org.tatools/sunshine-junit4.svg)](https://search.maven.org/search?q=g:%22org.tatools%22%20AND%20a:%22sunshine-junit4%22)|[![](https://img.shields.io/maven-central/v/org.tatools/sunshine-core.svg)](https://search.maven.org/search?q=g:%22org.tatools%22%20AND%20a:%22sunshine-core%22) | ||
Javadoc|[![](https://www.javadoc.io/badge/org.tatools/sunshine-testng.svg)](https://www.javadoc.io/doc/org.tatools/sunshine-testng)|[![](https://www.javadoc.io/badge/org.tatools/sunshine-junit4.svg)](https://www.javadoc.io/doc/org.tatools/sunshine-junit4)|[![](https://www.javadoc.io/badge/org.tatools/sunshine-core.svg)](https://www.javadoc.io/doc/org.tatools/sunshine-core) | ||
Since `0.4.x` version Sunshine uses `org.tatools` group ID. If you need the earlier version | ||
please use `io.github.tatools` instead. | ||
|
||
## `sunshine-core` | ||
Artifacts: | ||
[![](https://img.shields.io/maven-central/v/org.tatools/sunshine-core.svg)](https://search.maven.org/search?q=g:%22org.tatools%22%20AND%20a:%22sunshine-core%22) | ||
[![](https://www.javadoc.io/badge/org.tatools/sunshine-core.svg)](https://www.javadoc.io/doc/org.tatools/sunshine-core) | ||
|
||
`sunshine-junit4` was tested on `4.11` version of JUnit4 and `sunshine-testng` on `6.11` version of TestNG. | ||
## `sunshine-junit4` | ||
The library is tested on JUnit4 `4.11`. | ||
|
||
Since `0.4.x` version Sunshine uses `org.tatools` group ID. If you need the earlier version | ||
please use `io.github.tatools` instead. | ||
Artifacts: | ||
[![](https://img.shields.io/maven-central/v/org.tatools/sunshine-junit4.svg)](https://search.maven.org/search?q=g:%22org.tatools%22%20AND%20a:%22sunshine-junit4%22) | ||
[![](https://www.javadoc.io/badge/org.tatools/sunshine-junit4.svg)](https://www.javadoc.io/doc/org.tatools/sunshine-junit4) | ||
|
||
## `sunshine-junit5` | ||
Artifacts: | ||
[![](https://img.shields.io/maven-central/v/org.tatools/sunshine-junit5.svg)](https://search.maven.org/search?q=g:%22org.tatools%22%20AND%20a:%22sunshine-junit5%22) | ||
[![](https://www.javadoc.io/badge/org.tatools/sunshine-junit5.svg)](https://www.javadoc.io/doc/org.tatools/sunshine-junit5) | ||
|
||
## `sunshine-testng` | ||
The library is tested on TestNG `6.11`. | ||
|
||
Artifacts: | ||
[![](https://img.shields.io/maven-central/v/org.tatools/sunshine-testng.svg)](https://search.maven.org/search?q=g:%22org.tatools%22%20AND%20a:%22sunshine-testng%22) | ||
[![](https://www.javadoc.io/badge/org.tatools/sunshine-testng.svg)](https://www.javadoc.io/doc/org.tatools/sunshine-testng) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
dependencies { | ||
compileOnly 'org.projectlombok:lombok:1.16.14' | ||
annotationProcessor 'org.projectlombok:lombok:1.16.14' | ||
testCompileOnly 'org.projectlombok:lombok:1.16.14' | ||
testAnnotationProcessor 'org.projectlombok:lombok:1.16.14' | ||
compile 'org.junit.jupiter:junit-jupiter:5.5.2' | ||
compile 'org.junit.platform:junit-platform-launcher:1.5.2' | ||
testCompile 'org.hamcrest:hamcrest-all:1.3' | ||
} | ||
|
||
task ready(dependsOn: check) { | ||
doLast { | ||
println("Unit testing of Sunshine Junit5 is completed.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
NAME="Sunshine JUnit5 adapter" | ||
DESCRIPTION="The package is Sunshine's adapter for JUnit5 tests runner." |
84 changes: 84 additions & 0 deletions
84
sunshine-junit5/src/main/java/org/tatools/sunshine/junit5/Junit5Kernel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.tatools.sunshine.junit5; | ||
|
||
import org.junit.platform.engine.DiscoverySelector; | ||
import org.junit.platform.engine.discovery.DiscoverySelectors; | ||
import org.junit.platform.launcher.Launcher; | ||
import org.junit.platform.launcher.TestExecutionListener; | ||
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; | ||
import org.junit.platform.launcher.core.LauncherFactory; | ||
import org.junit.platform.launcher.listeners.SummaryGeneratingListener; | ||
import org.tatools.sunshine.core.*; | ||
|
||
/** | ||
* The class provides a {@link Kernel} implementation of JUnit 5 runner. | ||
* | ||
* @author Dmytro Serdiuk | ||
* @version $Id$ | ||
*/ | ||
public class Junit5Kernel implements Kernel<TestExecutionListener> { | ||
|
||
private final Launcher launcher; | ||
private final SunshineSuite tests; | ||
private final SummaryGeneratingListener reporter; | ||
|
||
/** | ||
* Initializes a newly created {@link Junit5Kernel} object so that it represents | ||
* an JUnit4 runner. | ||
* | ||
* @param sunshineSuite the suite with desired tests | ||
*/ | ||
public Junit5Kernel(SunshineSuite sunshineSuite) { | ||
this(LauncherFactory.create(), sunshineSuite); | ||
} | ||
|
||
/** | ||
* Initializes a newly created {@link Junit5Kernel} object so that it represents | ||
* an JUnit4 runner. | ||
* | ||
* @param launcher the launcher for a given test suite | ||
* @param sunshineSuite the suite with desired tests | ||
*/ | ||
private Junit5Kernel(Launcher launcher, SunshineSuite sunshineSuite) { | ||
this.tests = sunshineSuite; | ||
this.launcher = launcher; | ||
this.reporter = new SummaryGeneratingListener(); | ||
this.launcher.registerTestExecutionListeners(this.reporter); | ||
} | ||
|
||
/** | ||
* Returns a status of JUnite 5 tests execution. | ||
* | ||
* @return the status for the current execution | ||
* @throws KernelException if any error occurs during JUnit tests execution | ||
*/ | ||
@Override | ||
public final Status status() throws KernelException { | ||
try { | ||
launcher.execute( | ||
LauncherDiscoveryRequestBuilder.request() | ||
.selectors( | ||
tests.tests().stream().map( | ||
sunshineTest -> DiscoverySelectors.selectClass(sunshineTest.toString()) | ||
).toArray(DiscoverySelector[]::new) | ||
).build() | ||
); | ||
return new Junit5Status(this.reporter.getSummary()); | ||
} catch (SuiteException e) { | ||
throw new KernelException("Some problem occurs in the Junit5Kernel", e); | ||
} | ||
} | ||
|
||
/** | ||
* Returns a new instance of the JUnit 5 kernel with provided listeners based | ||
* on the current instance configuration. | ||
* | ||
* @param testExecutionListeners at least one desired listener | ||
* @return the new instance of the JUnit 5 kernel | ||
*/ | ||
@Override | ||
public final Kernel<TestExecutionListener> with(TestExecutionListener... testExecutionListeners) { | ||
final Launcher fork = LauncherFactory.create(); | ||
fork.registerTestExecutionListeners(testExecutionListeners); | ||
return new Junit5Kernel(fork, this.tests); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
sunshine-junit5/src/main/java/org/tatools/sunshine/junit5/Junit5Status.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.tatools.sunshine.junit5; | ||
|
||
import org.junit.platform.launcher.listeners.SummaryGeneratingListener; | ||
import org.junit.platform.launcher.listeners.TestExecutionSummary; | ||
import org.tatools.sunshine.core.Status; | ||
|
||
/** | ||
* The class provides an implementation of the {@link Status} for JUnit 5 execution. | ||
* | ||
* @author Dmytro Serdiuk | ||
* @version $Id$ | ||
*/ | ||
public class Junit5Status implements Status { | ||
private final TestExecutionSummary summary; | ||
private final short passed = 0; | ||
private final short failed = 1; | ||
|
||
/** | ||
* Initializes a newly created instance to represent a status of | ||
* JUnit 5 execution. | ||
* | ||
* @param testExecutionSummary the report provided by {@link SummaryGeneratingListener} | ||
*/ | ||
public Junit5Status(TestExecutionSummary testExecutionSummary) { | ||
this.summary = testExecutionSummary; | ||
} | ||
|
||
@Override | ||
public final short code() { | ||
return this.summary.getTotalFailureCount() == 0 ? this.passed : this.failed; | ||
} | ||
|
||
@Override | ||
public final int runCount() { | ||
return Math.toIntExact(this.summary.getTestsFoundCount()); | ||
} | ||
|
||
@Override | ||
public final int failureCount() { | ||
return Math.toIntExact(this.summary.getTestsFailedCount()); | ||
} | ||
|
||
@Override | ||
public final int ignoreCount() { | ||
return Math.toIntExact(this.summary.getTestsSkippedCount()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
sunshine-junit5/src/main/java/org/tatools/sunshine/junit5/Sunshine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.tatools.sunshine.junit5; | ||
|
||
|
||
import org.tatools.sunshine.core.*; | ||
|
||
/** | ||
* The {@link Sunshine} class is a main class to run JUnit 5 tests. | ||
* | ||
* @author Dmytro Serdiuk | ||
* @version $Id$ | ||
*/ | ||
public final class Sunshine { | ||
|
||
public static void main(String[] args) { | ||
new Sun( | ||
new Junit5Kernel( | ||
new SunshineSuitePrintable( | ||
new SunshineSuiteFilterable( | ||
new SuiteFromFileSystem( | ||
new FileSystemOfClasspathClasses() | ||
), | ||
new VerboseRegex(new RegexCondition()) | ||
) | ||
) | ||
) | ||
).shine(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
sunshine-junit5/src/main/java/org/tatools/sunshine/junit5/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* The main package of the integration with JUnit 5. | ||
* | ||
* @author Dmytro Serdiuk | ||
* @version $Id$ | ||
*/ | ||
package org.tatools.sunshine.junit5; |
47 changes: 47 additions & 0 deletions
47
sunshine-junit5/src/test/java/org/tatools/sunshine/junit5/Junit5KernelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.tatools.sunshine.junit5; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.platform.engine.TestExecutionResult; | ||
import org.junit.platform.launcher.TestExecutionListener; | ||
import org.junit.platform.launcher.TestIdentifier; | ||
import org.tatools.sunshine.core.KernelException; | ||
|
||
import java.util.ArrayList; | ||
|
||
|
||
/** | ||
* @author Dmytro Serdiuk | ||
* @version $Id$ | ||
*/ | ||
public class Junit5KernelTest { | ||
|
||
@Test | ||
public void run() throws KernelException { | ||
MatcherAssert.assertThat( | ||
new Junit5Kernel(ArrayList::new).status().code(), | ||
Matchers.equalTo((short) 0) | ||
); | ||
} | ||
|
||
|
||
@Test | ||
public void with() throws KernelException { | ||
final Listener l1 = new Listener(); | ||
final Listener l2 = new Listener(); | ||
new Junit5Kernel(ArrayList::new).with(l1).with(l2).status(); | ||
MatcherAssert.assertThat(l1, Matchers.not(Matchers.equalTo(l2))); | ||
} | ||
|
||
@EqualsAndHashCode | ||
private final class Listener implements TestExecutionListener { | ||
private int call = 0; | ||
|
||
@Override | ||
public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { | ||
this.call = 1; | ||
} | ||
} | ||
} |
Oops, something went wrong.