= Testing with JUnit4 Sample

[.download]
- link:zips/sample_java_components_with_junit4_tests-groovy-dsl.zip[icon:download[] Groovy DSL]
- link:zips/sample_java_components_with_junit4_tests-kotlin-dsl.zip[icon:download[] Kotlin DSL]

NOTE: You can open this sample inside an IDE using the https://www.jetbrains.com/help/idea/gradle.html#gradle_import_project_start[IntelliJ native importer] or https://projects.eclipse.org/projects/tools.buildship[Eclipse Buildship].

This sample shows how to test Java projects with link:https://junit.org/junit4/[JUnit4] in Gradle.

For applications:

====
include::sample[dir="samples/java-components-with-jUnit4Tests/groovy",files="application/build.gradle[]"]
include::sample[dir="samples/java-components-with-jUnit4Tests/kotlin",files="application/build.gradle.kts[]"]
====

For libraries:

====
include::sample[dir="samples/java-components-with-jUnit4Tests/groovy",files="list/build.gradle[]"]
include::sample[dir="samples/java-components-with-jUnit4Tests/kotlin",files="list/build.gradle.kts[]"]
====

Running the tests:

====
[.testable-sample,dir="groovy"]
=====
[.sample-command]
----
$ ./gradlew test

BUILD SUCCESSFUL in 7s
7 actionable tasks: 7 executed
----
=====
====

For more information, see link:{userManualPath}/java_testing.html[Testing in Java project chapter].

You can also generate this project locally using link:{userManualPath}/build_init_plugin.html#sec:java_application[`gradle init`].
