Coder Social home page Coder Social logo

Comments (2)

oleosterhagen avatar oleosterhagen commented on June 16, 2024 4

Thank you @howlger for your detailed analyses.

As mentioned, when the junit-platform-launcher is missing on the launch configuration classpath, Eclipse adds its internal junit-platform-launcher, which may be not compatible with the used junit-jupiter version:

https://github.com/eclipse-jdt/eclipse.jdt.ui/blob/055a935ec3f04c17f5b1ba6a2a8c95380ca5226c/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationDelegate.java#L200-L208

With Maven this is no problem, because m2e adds the missing JUnit launcher with a matching version:

https://github.com/eclipse-m2e/m2e-core/blob/ac7bf50bb5318285470a065f1981ca4dd91aa241/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java#L274-L277

The clean way to solve this problem with Gradle/Buildship is to include the missing org.junit.platform:junit-platform-launcher dependency in build.gradle (see Manually declaring dependencies). This is automatically done when you create a project with the Gradle Build Init Plugin from newer Gradle distributions:

dependencies {
    // Use JUnit Jupiter for testing.
    testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'

    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
[...]

Unfortunately, when you do not change the Gradle version in Window > Preferences > Gradle the New Gradle Project Wizard in Buildship uses Gradle 8.1.1 and the Build Init Plugin from this distribution does not add this dependency. In my opinion, this gives not the best first-time user experience.

The execution of JUnit tests on command line or with Run As > Gradle Test is no problem, because then the missing dependency is added at runtime. But this feature is deprecated and will be removed:

> Task :lib:test
The automatic loading of test framework implementation dependencies has been deprecated. This is scheduled to be removed in Gradle 9.0. Declare the desired test framework directly on the test suite or explicitly declare the test framework implementation dependencies on the test's runtime classpath. Consult the upgrading guide for further information: https://docs.gradle.org/8.3/userguide/upgrading_version_8.html#test_framework_implementation_dependencies

To improve the first-time user experience in Eclipse, Buildship should be updated to reference a newer Gradle distribution.

from buildship.

djkdevise avatar djkdevise commented on June 16, 2024

En mi caso particular este error se soluciono siguiendo estos pasos: Una vez abierto el proyecto, haz clic derecho sobre él y elige Properties -> Java Build Path. Activa la pestaña Libraries y haz clic sobre Add Library… Selecciona JUnit -> Next -> Finish -> Apply and close

Recuerda que también puedes añadir la librería a través de Maven, pero yo he añadido la librería de esta forma, que es igual de válida.

Observa que se han añadido todas las librerías correspondientes a JUnit 5 a tu proyecto.

tomado de: https://developrogramming.com/testear-con-junit-5/

from buildship.

Related Issues (20)

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.