Git Product home page Git Product logo

junit5-samples's Introduction

JUnit 5 Samples ci-badge

Welcome to JUnit 5 Samples, a collection of sample applications and extensions using JUnit Jupiter, JUnit Vintage, and the JUnit Platform on various build systems.

CI builds for sample projects are performed by GitHub Actions. Using JDK 11+'s jshell tool, you may build all samples via the build-all-samples.jsh script.

Jupiter Starter Samples

Basic setups showing how to get started with JUnit Jupiter.

Jupiter on Ant badge-jdk-8 badge-tool-ant badge-junit-jupiter

The junit5-jupiter-starter-ant sample demonstrates the bare minimum configuration for getting started with JUnit Jupiter using the Ant build system.

Jupiter on Gradle badge-jdk-8 badge-tool-gradle badge-junit-jupiter

The junit5-jupiter-starter-gradle sample demonstrates the bare minimum configuration for getting started with JUnit Jupiter using the Gradle build system.

Jupiter on Gradle using Kotlin badge-jdk-8 badge-tool-gradle badge-junit-jupiter

The junit5-jupiter-starter-gradle-kotlin sample demonstrates the bare minimum configuration for getting started with JUnit Jupiter using the Gradle build system and the Kotlin programming language.

Jupiter on Gradle using Groovy badge-jdk-8 badge-tool-gradle badge-junit-jupiter

The junit5-jupiter-starter-gradle-groovy sample demonstrates the bare minimum configuration for getting started with JUnit Jupiter using the Gradle build system and the Groovy programming language.

Jupiter on Maven badge-jdk-8 badge-tool-maven badge-junit-jupiter

The junit5-jupiter-starter-maven sample demonstrates the bare minimum configuration for getting started with JUnit Jupiter using the Maven build system.

Jupiter on Maven using Kotlin badge-jdk-8 badge-tool-maven badge-junit-jupiter

The junit5-jupiter-starter-maven-kotlin sample demonstrates the bare minimum configuration for getting started with JUnit Jupiter project using Maven build system and Kotlin programming language.

Jupiter on Bazel badge-jdk-8 badge-tool-bazel badge-junit-jupiter

The junit5-jupiter-starter-bazel sample demonstrates the bare minimum configuration for getting started with JUnit Jupiter using the Bazel build system.

Jupiter on sbt badge-jdk-8 badge-tool-sbt badge-junit-jupiter

The junit5-jupiter-starter-sbt sample demonstrates the bare minimum configuration for getting started with JUnit Jupiter using sbt and the Scala programming language.

Jupiter Feature Samples

Extending JUnit Jupiter using its Extension API.

Sample Extensions badge-jdk-8 badge-tool-gradle badge-junit-jupiter

The junit5-jupiter-extensions sample demonstrates how one can implement custom JUnit Jupiter extensions and use them in tests.

Migration Samples

More complex setups how to integrate various parts of "JUnit 5" including a possible migration path for JUnit 3 or 4 based projects.

Gradle Migration badge-jdk-8 badge-tool-gradle badge-junit-platform badge-junit-jupiter badge-junit-vintage

The junit5-migration-gradle sample demonstrates how to set up a Gradle project using the JUnit Platform, JUnit Jupiter, and JUnit Vintage.

Maven Migration badge-jdk-8 badge-tool-maven badge-junit-platform badge-junit-jupiter badge-junit-vintage

The junit5-migration-maven sample demonstrates how to set up a Maven project using the JUnit Platform, JUnit Jupiter, and JUnit Vintage.

Platform Samples

Showing basic features of the JUnit Platform.

Multiple Engines badge-jdk-11 badge-tool-gradle badge-junit-platform badge-junit-jupiter badge-junit-vintage ...

The junit5-multiple-engines sample demonstrates how to set up a Gradle project using the JUnit Platform with various TestEngine implementations.

Living in the Modular World badge-jdk-11 badge-tool-console badge-junit-platform

The junit5-modular-world sample demonstrates how to test code organized in modules. This sample also demonstrates how to implement a custom TestEngine for the JUnit Platform using the Java Platform Module System.

junit5-samples's People

Contributors

alilosoft avatar arend-von-reinersdorff avatar britter avatar chenrui333 avatar daggerok avatar dependabot[bot] avatar eddumelendez avatar eriwen avatar goerge avatar hcoona avatar hiepluong2205 avatar igorwojda avatar jbduncan avatar jlink avatar jlleitschuh avatar juanmorenodeveloper avatar junit-builds avatar limitedatonement avatar marcphilipp avatar minidigger avatar msauza avatar natansil avatar oohira avatar ors-woon avatar sbrannen avatar smoyer64 avatar snicoll avatar sormuras avatar ssoloff avatar szpak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

junit5-samples's Issues

Consider moving to a public domain licence

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.

Build fails on JDK 9

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.

Update JUnit 5 dependency recommendations in POM

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

Please cite best practice for not excluding maven-wrapper.jar

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

Maven Surefire 2.22.1 fails on Debian

$ 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?

Add snapshot repositories to POM

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>

Add Ant-wrapper to junit5-jupiter-starter-ant

Overview

The junit5-jupiter-starter-ant build process relies on pre install actions executed by its build.sh. These actions are:

  • Load and extract Ant binary distro from Apache mirror to the local workspace.
  • Load and store junit-platform-console-standalone jar in local ant installation.
  • Call ant with default test task.

The first two steps need to be replaced with Ant Wrapper feature.

Deliverables

  • Add some antw support and make sure everythings builds fine.
  • Include junit5-jupiter-starter-ant in build-all-samples program.

Warnings in Gradle Consumer about API constants

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.

Support custom Gradle test tasks

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?

ClasspathScanner loads all classes causing class visibility side effects

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.

Missing assertThrow() / assertDoesNotThrowโ€‹() / assertAll() examples

To check exceptions use:

See also my example snippet:
https://stackoverflow.com/a/51768474/938111

Remove 'java' from junit5-jupiter-starter-maven-kotlin

It should, like the junit5-jupiter-starter-gradle-kotlin project, only contain the following directories:

Main

  • src/main/kotlin
  • src/test/kotlin

Deliverables

  • Remove java from junit5-jupiter-starter-maven-kotlin sample project.
  • Trim pom.xml down to the minimum of configurations needed to get Maven + Kotlin + Jupiter happy.

Introduce multi-module Gradle sample application

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.

Cannot create Launcher without at least one TestEngine

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)

Upgrade licenses to EPL v2

Deliverables

  • Update license in root directory to EPL v2
  • Remove license files in sub-directories

Projects Already Using EPL v2

  • junit5-gradle-consumer
  • junit5-maven-consumer
  • junit5-mockito-extension
  • junit5-vanilla-gradle
  • junit5-vanilla-maven
  • junit5-vanilla-modules
  • junit5-java9-engine

Alter junit5-maven-consumer POM to demonstrate including and excluding @Tags

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.

Please provide vanilla samples

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?

Deliverables

  • Vanilla Gradle project
  • Vanilla Maven project

mvnDebug for the junit5-maven-consumer sample doesn't hit breakpoint

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?

gradle plugin should be published to https://plugins.gradle.org/

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'
}

Add Android integration test project

Description

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.

Deliverables

Update README for junit5-migration-gradle regarding Gradle test task

Overview

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+.

Deliverables

  • Update the README for junit5-migration-gradle regarding the Gradle test task.

Add `junit5-migration-maven-kotlin` sample

junit5-migration-maven-kotlin

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

Discrepancy between sample and user guide

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?

junit5-jupiter-starter-maven out of date?

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.

Store is misused in MockitoExtension

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.

Consider running Bazel sample with Bazelisk

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:

  1. Require that the user has Python installed to build the samples.
  2. See if running Bazelisk on Jython would work.
  3. Wait until a Go version or similar is released, eliminating the need to install Python.

I'd love to hear the JUnit 5 team's thoughts regarding all this. :)

Enable snapshot repo for plugins

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.

Unable to resolve the new junit-jupiter aggregator dependency via Gradle

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?

Rename sample projects

Jupiter-only Starters

Purpose: Demonstrate how to start a new project using Jupiter. Vanilla-style.

  • junit5-jupiter-starter-ant (using Ant 1.10.3 and ConsoleLauncher)
  • junit5-jupiter-starter-gradle from junit5-vanilla-gradle (using Gradle 4.6 w/ useJUnitPlatform)
  • junit5-jupiter-starter-maven from junit5-vanilla-maven

Jupiter-only Feature Samples

Purpose: Demonstrate how to use and extend use various Jupiter features.

  • junit5-jupiter-extensions RandomExtension, CartesianProductTest, ...

Migration Samples

Purpose: Demonstrate how to use various parts of JUnit 5 including a possible migration path for JUnit 3/4 based projects. Vintage + Jupiter

  • junit5-migration-gradle from junit5-gradle-consumer (using Gradle 4.6 w/ useJUnitPlatform)
  • junit5-migration-maven from junit5-gradle-maven

Modular Samples

Purpose: Living in the Modular World...

  • junit5-modular-world merge of junit5-java9-engine and junit5-vanilla-modules

Example of using Dependency Injection needed

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.

Create example for TemporaryFolder extension

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();
  }
}

LICENSE.md is missing as well as TOF comment referencing copyright and license

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.