junit-team / junit5-samples Goto Github PK
View Code? Open in Web Editor NEWCollection of sample applications using JUnit 5.
License: Eclipse Public License 2.0
Collection of sample applications using JUnit 5.
License: Eclipse Public License 2.0
Hey,
I am running the following in gradle:
junitPlatform {
filters {
engines {
include 'junit-platform', 'junit-vintage', 'junit-jupiter'
}
tags {
include 'categories.TestClassifier.ReliableIntegrationTest'
}
}
}
I believe I have configured the dependencies correctly:
dependencies {
classpath (
"org.junit.platform:junit-platform-gradle-plugin:1.0.0-M3",
)
}
apply plugin: "org.junit.platform.gradle.plugin"
configurations {
externalLibraries
compile.extendsFrom (externalLibraries)
}
externalLibraries (group: 'org.junit.platform', name: 'junit-platform-commons', version: '1.0.0-M3')
externalLibraries (group: 'org.junit.platform', name: 'junit-platform-console', version: '1.0.0-M3')
externalLibraries (group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.0.0-M3')
externalLibraries (group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.0.0-M3')
externalLibraries (group: 'org.junit.platform', name: 'junit-platform-gradle-plugin', version: '1.0.0-M3')
externalLibraries (group: 'org.junit.platform', name: 'junit-platform-engine', version: '1.0.0-M3')
externalLibraries (group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '4.12.0-M3')
externalLibraries (group: 'junit', name: 'junit', version: '4.12')
externalLibraries (group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.0-M3')
externalLibraries (group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.0.0-M3')
No matter how I adjust the engines (specify just one engine, list all or comment out the engine part entirely) I always run in this error:
Feb 22, 2017 3:21:14 PM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
INFO: No TestEngine implementation discovered.
org.junit.platform.commons.util.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath
at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:207)
at org.junit.platform.launcher.core.DefaultLauncher.<init>(DefaultLauncher.java:52)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:53)
at org.junit.platform.console.tasks.ExecuteTestsTask.executeTests(ExecuteTestsTask.java:61)
at org.junit.platform.console.tasks.ExecuteTestsTask.lambda$execute$0(ExecuteTestsTask.java:57)
at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.invoke(CustomContextClassLoaderExecutor.java:33)
at org.junit.platform.console.tasks.ExecuteTestsTask.execute(ExecuteTestsTask.java:57)
at org.junit.platform.console.tasks.ConsoleTaskExecutor.executeTask(ConsoleTaskExecutor.java:38)
at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:54)
at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:39)
The junit5-migration-maven-kotlin
project demonstrates how to execute tests written in Java and Kotlin based on JUnit 5 using Maven. In addition, it showcases that existing JUnit 4 based tests can be executed in the same test suite as JUnit Jupiter based tests or any other tests supported on the JUnit Platform.
Main
src/main/java/.../Calculator.java
src/main/kotlin/.../Kalculator.kt
Test
src/test/java/.../CalculatorTests.java
src/test/java/.../JUnit4Test.java
src/test/kotlin/.../KalculatorTests.kt
src/test/java/.../JUnit4Test.kt
Can you please provide vanilla samples that demonstrates what a user should do to get started with JUnit5 (and only that?). The current sample mixes different concerns and while they are separated from the pom, the changes in JUnit5 are significant enough to deserve a dedicated sample IMO.
The installation section in the documentation is a bit confusing, I am not sure that listing all the jars that the JUnit distribution now ships is the most important information to get started. It then redirects to the two samples (which is why I am creating an issue here).
On a related note, it looks like the Spring Boot project has a vanilla sample (at least the build part). Can you please confirm that adding 3 jars manually is what needs to be done?
Should there be same test examples in both maven and gradle consumers?
Assuming this project is supposed to have the same licensing as the junit5 project, a copy of LICENSE.md should be placed in the project and the rest of the files should have top-of-file licenses added (I noticed it was missing from junit5-mockito-extension/build.gradle but the TOF license comments are present on many of the Java files I looked at.
Since its a dependency of "junit-jupiter-engine" which is already added as in the project.
See here:
Migrating my Tests from JUnit 4 got stuck because my productive code (not test code) contains a class that MUST be loaded with the system/bootstrap class loader (the code is quite complex).
JUnit Jupiter seems to scan all classes and loads them with the current classloader. The latter is a problem for me, because an already loaded class shadows the one which is loaded later on (in the test) by the system classloader (meaning that the test operates on a different class than the rest of the program).
Maybe it would be better to do classpath scanning in a separate classloader (and reload only those classes that were qualified by the scanner).
If you are interested in an example I will prepare a branch in my github project to contain only the classes that provoke this error.
Regarding this file .mvn/wrapper/maven-wrapper.jar
It is excluded in https://github.com/github/gitignore/blob/master/Maven.gitignore
But not excluded at https://github.com/junit-team/junit5-samples/blob/master/junit5-jupiter-starter-maven/.gitignore
Could reference (blog post, article, documentation, etc.) to a best practice please be provided as to why this choice is made and link added to https://github.com/junit-team/junit5-samples/blob/master/junit5-jupiter-starter-maven/.gitignore
In support of the documentation change described by junit-team/junit5#292.
instead of forcing gradle users to use the old notation for plugins i.e.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4'
}
}
apply plugin: 'org.junit.platform.gradle.plugin'
you should instead publish to https://plugins.gradle.org/ so that gradle users can use the much preferred syntax of
plugins {
id 'org.junit.platform.gradle.plugin' version '1.0.0-M4'
}
I've forked this https://github.com/junit-team/junit5-samples/tree/master/junit5-jupiter-starter-ant
I then added a sample Junit4 test under test junit5-jupiter-starter-ant/src/test/java/com/example/project/
Launcher o/p:
Ran the build.sh expecting the vintage engine to show the run o/p.
When I submitted PR #16 (Alters POM to minimize test-compile dependencies), I purposely included only the junit-jupiter-api
artifact as a test-scoped dependency and included the other packages that were needed at test-execution time as a dependency of the maven-surefire-plugin
. My intention was to only expose the classes in junit-jupiter-api
to the test writer's test compiler.
In this comment, @Tibor17 has instructed that this is not the correct configuration and that only the junit-platform-surefire-provider
should be a plugin dependency. I'll let @Tibor17 comment on why this is important if he chooses.
Related to junit-team/junit5#848
This repository contains samples that people copy & paste for their projects. Having the current license adds an unnecesary burden to make sure that whatever they copy, have the correct license in place.
Consider changing the license to one that people can copy & paste samples without having to worrying about making sure that the corresponding license is preserved.
I tried updating my project from junit 5.3.2 to 5.4.0 but I have been running into this error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestJava'.
> Could not resolve all files for configuration ':testCompileClasspath'.
> Could not resolve org.junit.jupiter:junit-jupiter:5.4.0.
Required by:
project :
> Could not resolve org.junit.jupiter:junit-jupiter:5.4.0.
> Could not parse POM https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter/5.4.0/junit-jupiter-5.4.0.pom
> Content is not allowed in prolog.
> Could not resolve org.junit.jupiter:junit-jupiter:5.4.0.
> Could not parse POM https://jcenter.bintray.com/org/junit/jupiter/junit-jupiter/5.4.0/junit-jupiter-5.4.0.pom
> Content is not allowed in prolog.
I also downloaded the samples and tried those with same result.
MINGW64 ~/Downloads/junit5-samples-master/junit5-jupiter-starter-gradle
$ ./gradlew clean test
> Task :clean
> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :compileTestJava
[Fatal Error] junit-jupiter-5.4.0.pom:2:1: Content is not allowed in prolog.
[Fatal Error] junit-jupiter-5.4.0.pom:2:1: Content is not allowed in prolog.
[Fatal Error] junit-jupiter-5.4.0.pom:2:1: Content is not allowed in prolog.
> Task :compileTestJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestJava'.
> Could not resolve all files for configuration ':testCompileClasspath'.
> Could not resolve org.junit.jupiter:junit-jupiter:5.4.0.
Required by:
project :
> Could not resolve org.junit.jupiter:junit-jupiter:5.4.0.
> Could not parse POM https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter/5.4.0/junit-jupiter-5.4.0.pom
> Content is not allowed in prolog.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
3 actionable tasks: 3 executed
MINGW64 ~/Downloads/junit5-samples-master/junit5-jupiter-starter-gradle-kotlin
$ ./gradlew clean test
> Task :clean
> Task :compileKotlin
> Task :compileJava NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :compileTestKotlin
[Fatal Error] junit-jupiter-5.4.0.pom:2:1: Content is not allowed in prolog.
[Fatal Error] junit-jupiter-5.4.0.pom:2:1: Content is not allowed in prolog.
[Fatal Error] junit-jupiter-5.4.0.pom:2:1: Content is not allowed in prolog.
> Task :compileTestKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestKotlin'.
> Could not resolve all files for configuration ':testCompileClasspath'.
> Could not resolve org.junit.jupiter:junit-jupiter:5.4.0.
Required by:
project :
> Could not resolve org.junit.jupiter:junit-jupiter:5.4.0.
> Could not parse POM https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter/5.4.0/junit-jupiter-5.4.0.pom
> Content is not allowed in prolog.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4s
3 actionable tasks: 3 executed
The junit5-jupiter-starter-maven sample works as expected.
Since I cannot find anything on google about this error, there must be something on my machine or something that I am doing wrong.
Does anyone have an idea what the problem might be?
Can anyone else reproduce this issue with the Gradle samples?
I am fixing a project with junit jupiter 5.2.0, but I cannot build it. The build had a more tedious configuration earlier and after issues with compiled build, I am trying to resolve this...
However: Compiling the code works fine, but tests are not even executed as the surefire-plugin throws an exception with no details in the message. There are no warnings/errors prior to this message.
The exceptuion:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project jactor-commons: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test failed.: IllegalArgumentException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project jactor-commons: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.parse(AsmModuleInfoParser.java:89)
at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.getModuleDescriptor(AsmModuleInfoParser.java:54)
at org.codehaus.plexus.languages.java.jpms.LocationManager.resolvePaths(LocationManager.java:83)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.newStartupConfigForModularClasspath(AbstractSurefireMojo.java:1765)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.createStartupConfiguration(AbstractSurefireMojo.java:1708)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.createForkStarter(AbstractSurefireMojo.java:2043)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1146)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:978)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:854)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
The GitHub branch with the code: https://github.com/jactor-rises/jactor-rises/tree/feature/5_configuration
The issue trying to be resolved:jactor-rises/jactor-rises#5
Even though junit.jupiter is written for java 1.8, I do not think that my code is "revolutionary" so it cannot be executed despite of it being java 10. What might be the problem.
The Maven consumer needs JUnit5-Surefire in version 5.0.0-SNAPSHOT
, which is only available in the snapshot repo. But it is not configured for plugins (only for regular dependencies).
I had to change this ...
<repositories>
<repository>
<id>snapshots-repo</id>
<!-- snip -->
</repository>
</repositories>
... to this ...
<pluginRepositories>
<pluginRepository>
<id>snapshots-repo</id>
<!-- snip -->
</pluginRepository>
</pluginRepositories>
... to make mvn test
work.
Adding the following to pom.xml
allows the project to build successfully.
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</pluginRepository>
</pluginRepositories>
When the junit5-platform-surefire-provider is updated by PR junit-team/junit5#485 it will be capable of enabling and disabling tests using include and exclude filters. Examples of the POM configuration that allows this functionality should be added to the junit5-maven-consumer example (along with tests that conform to the filters).
Please assign this to me as I've got enough code to demonstrate these new capabilities in a feature branch. With some clean-up, it should meet the JUnit 5 code standards.
To check exceptions use:
assertAll()
Asserts that all supplied executables
do not throw exceptions.
assertDoesNotThrow()
Asserts that execution of the supplied executable
/supplier
does not throw any kind of exception.
assertThrows()
Asserts that execution of the supplied executable
throws an exception of the expectedType
and returns the exception.
See also my example snippet:
https://stackoverflow.com/a/51768474/938111
Likely due to junit-team/junit5#1065 the build of the Gradle Consumer shows some warnings about unknown API constants. See Travis Build:
Task :compileTestJava
warning: unknown enum constant Status.STABLE
reason: class file for org.apiguardian.api.API$Status not found
warning: unknown enum constant Status.STABLE
warning: unknown enum constant Status.STABLE
warning: unknown enum constant Status.STABLE
warning: unknown enum constant Status.STABLE
warning: unknown enum constant Status.STABLE
6 warnings
This might be confusing for someone using the Gradle Consumer as a template.
I am using Gradle plugin. Standard -Dtest.debug is not working. ALso my IntelliJ Idea can't run tests in debug. Not clear how to run tests in debug mode
Purpose: Demonstrate how to start a new project using Jupiter. Vanilla-style.
Purpose: Demonstrate how to use and extend use various Jupiter features.
Purpose: Demonstrate how to use various parts of JUnit 5 including a possible migration path for JUnit 3/4 based projects. Vintage + Jupiter
Purpose: Living in the Modular World...
What would an implementation outline look like?
Usage:
@ExtendWith(TemporaryFolder.class)
public class TempTest {
// ...
@Test
void temp(@TemporaryFolder.Tag TemporaryFolder temp) throws IOException {
System.out.println(temp.getRoot());
}
}
Implementation ("copied" from JUnit 4, stripped ExternalResource dependency):
public class TemporaryFolder implements MethodParameterResolver, AfterAllExtensionPoint {
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface Tag { }
// ...
@Override
public Object resolve(Parameter parameter, MethodInvocationContext mci, ExtensionContext ec)
throws ParameterResolutionException {
try {
create();
} catch (IOException e) {
throw new ParameterResolutionException(e.toString());
}
return this;
}
@Override
public boolean supports(Parameter parameter, MethodInvocationContext mci, ExtensionContext ec)
throws ParameterResolutionException {
return parameter.isAnnotationPresent(Tag.class);
}
@Override
public void afterAll(ContainerExtensionContext arg0) throws Exception {
delete();
}
}
Hello,
can someone help to make simple junit5
test work?
Here is link to bug-demmo repo.
https://github.com/le93us/junit5-maven-bug
I have a custom integration test task in my gradle build file:
task integrationTest(type:Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
}
How do I configure it so that it will run JUnit 5 tests using the plugin?
Directory https://github.com/junit-team/junit5/tree/master/platform-tooling-support-tests/projects already contains various gradle-xxx
projects, but none using an Android environment.
https://github.com/junit-team/junit5-samples should also include an Android-based sample project.
The maven-surefire-plugin version 2.20 includes the "**/*Tests.java" pattern, so the "includes" element can be removed from the plugin's configuration section.
The Gradle project in the sample does not follow recommendations (at least Android) on how the structure should look like for a new project.
Current project structure:
root\build.gradle
root\src\...
Preferred project structure (can easily be extended with more modules. application is the first...):
root\build.gradle
root\application\build.gradle
root\application\src\...
The reason why I think this is a problem is that I don't think it's obvious how the sample configuration should be applied to minimize code duplication in a multi-module project.
It would be cleaner to use @Mock
instead of JUnit's custom @InjectMock
annotation to request mock creation for both FIELD
and PARAMETER
declarations.
This feature request is currently blocked by mockito/mockito#438.
The README.md
file for the junit5-migration-gradle
project still documents the use of the junit-platform-gradle-plugin
; whereas, build.gradle
has been updated to make use of the built-in support for the JUnit Platform in Gradle 4.6+.
junit5-migration-gradle
regarding the Gradle test
task.$ mvn test
$ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] --------------< com.example:junit5-jupiter-starter-maven >--------------
[INFO] Building junit5-jupiter-starter-maven 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ junit5-jupiter-starter-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/alex/Desktop/junit5-samples/junit5-jupiter-starter-maven/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ junit5-jupiter-starter-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/alex/Desktop/junit5-samples/junit5-jupiter-starter-maven/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ junit5-jupiter-starter-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/alex/Desktop/junit5-samples/junit5-jupiter-starter-maven/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ junit5-jupiter-starter-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/alex/Desktop/junit5-samples/junit5-jupiter-starter-maven/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ junit5-jupiter-starter-maven ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.525 s
[INFO] Finished at: 2018-11-21T23:07:04+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project junit5-jupiter-starter-maven: There are test failures.
[ERROR]
[ERROR] Please refer to /home/alex/Desktop/junit5-samples/junit5-jupiter-starter-maven/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /home/alex/Desktop/junit5-samples/junit5-jupiter-starter-maven && /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -jar /home/alex/Desktop/junit5-samples/junit5-jupiter-starter-maven/target/surefire/surefirebooter7340559277676520476.jar /home/alex/Desktop/junit5-samples/junit5-jupiter-starter-maven/target/surefire 2018-11-21T23-07-02_952-jvmRun1 surefire194873160210424536tmp surefire_03951357035306538352tmp
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /home/alex/Desktop/junit5-samples/junit5-jupiter-starter-maven && /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -jar /home/alex/Desktop/junit5-samples/junit5-jupiter-starter-maven/target/surefire/surefirebooter7340559277676520476.jar /home/alex/Desktop/junit5-samples/junit5-jupiter-starter-maven/target/surefire 2018-11-21T23-07-02_952-jvmRun1 surefire194873160210424536tmp surefire_03951357035306538352tmp
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:669)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:282)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:245)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1183)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1011)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:857)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:954)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
$ mvn --version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T21:33:14+03:00)
Maven home: /home/alex/.sdkman/candidates/maven/current
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.9.0-8-amd64", arch: "amd64", family: "unix"
Can someon help to fix it?
I seem to remember that the JShell-based samples were unable to run Bazel because it was difficult to find a way of running Bazel locally on a developer's machine without pre-installing it. However, I've recently learned of a potential solution called Bazelisk, which is similar to Gradle's wrapper in that it downloads and installs Bazel at runtime before running Bazel commands.
However, although I think that Bazelisk should be considered, it's worth noting that it currently needs Python to work, but the author has expressed in the README that they may want to write a Go version in the future. So if the JUnit 5 team is interested in using Bazelisk, then I see three options:
I'd love to hear the JUnit 5 team's thoughts regarding all this. :)
The compute method on the maps require unboxing and boxing since the rely on the standard JDK 8 BiFunction instead of generating primitive type specific a BiFunction for each use case.
The ConsoleLauncher
is no longer necessary, since Ant provides built-in support for the JUnit Platform.
One runs mvnDebug test
and as expected it waits for you to attache a debugger to port 8000.
You go ahead and do that - with a breakpoint set on line 26 of FirstTest.java and it does not land on the breakpoint.
I wasn't expecting full integration with Intellij to be working, but this issue isn't about that, it's about a more basic use: Maven fully in charge of the test site invocation, and Intellij being asked to watch classes being instantiated and pertinent lines to be hit. It is missing them. Is Junit5 doing something with classloaders that 4.x wasn't previously?
Currently blocked by junit-team/junit5#286
Since the Mockito team has released official support for JUnit Jupiter, we should deprecate and eventually remove the example MockitoExtension
in this repository.
MockitoExtension
within the junit5-samples
repository.I realize that MockitoExtension should not be considered for production use but the way the ExtensionContext.Store is used isn't a good example of why a Store should be used. With the existing code, it's possible to return two references to the same object if the same Java class is "injected" into a test method twice. For instance:
@ExtendWith(MockitoExtension.class)
public class MockitoExtensionMisuse {
@Test
public void testSomethingWithTwoProperties(@InjectMock Properties properties1, @InjectMock Properties properties2) {
...
}
}
In the testSomethingWithTwoProperties() method, both properties1 and properties2 will be references to the same instance.
To check pull requests before merging them it would be great if we had a Travis build that builds all modules.
This sample does not have a test
scope for the two last dependencies.
I am assuming this is an oversight.
It should, like the junit5-jupiter-starter-gradle-kotlin
project, only contain the following directories:
Main
src/main/kotlin
src/test/kotlin
java
from junit5-jupiter-starter-maven-kotlin
sample project.pom.xml
down to the minimum of configurations needed to get Maven + Kotlin + Jupiter happy.For example, ChromeDriver (Selenium-WebDriver) browser frame instantiated once, and injected through constructors into a bunch of tests classes, and used for multiple methods within each. :)
Not pure unit tests as such, but JUnit is the classic runner for later steps in a build pipeline, and that includes service and UI clicking tests.
The user guide indicates that both junit-platform-surefire-provider
and junit-jupiter-engine
should be dependencies of the maven-surefire-plugin
plugin, and the code should just depend on junit-jupiter-api
(for simple cases).
The sample referenced by the user guide rather uses junit-jupiter-engine
as a global dependency.
The current sample depend globally on junit-jupiter-api
, junit-jupiter-engine
and junit-jupiter-params
, and does not mention junit-platform-surefire-provider
at all. I guess that the supplementary dependency on junit-jupiter-params
is there because the test is parameterized. But what about the other differences? What is the recommended configuration for a simple project using junit5?
Can you possibly change or comment the sources of information so that they match or we understand why they differ?
Hello,
I am not able to get this example working on ant 1.10.5 . I have added the required jars but it does not recognize ParametrizedTests and CsvSource
Could you please help?
While ./gradlew test
works on junit5-gradle-consumer
if using JDK8; once the user upgrades to JDK9, it breaks:
Could not create an instance of type com.sun.tools.javac.api.JavacTool.
The same is not true of junit4.
The junit5-jupiter-starter-ant
build process relies on pre install actions executed by its build.sh
. These actions are:
junit-platform-console-standalone
jar in local ant installation.ant
with default test
task.The first two steps need to be replaced with Ant Wrapper feature.
antw
support and make sure everythings builds fine.junit5-jupiter-starter-ant
in build-all-samples program.A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.