junit5

How do I open packages and require dependencies on test scope modules only for JUnit testing

安稳与你 提交于 2019-12-01 16:56:48
I'm migrating a jar project from java 10 using classpath to java 11 using the java 9 jigsaw modules. There are JUnit5 tests for the project. The test dependencies are provided at test scope by maven. How to make all packages open for testing but not open when the module is used by another project? The jar project is just providing a few classes (like a utility project) for other projects (so no main class needed). The project got 5 packages at /src/main/java/a/b/c/ . 2 of them should be accessible for projects using this jar. The other 3 are for internal use only (used by the accessible ones).

How do I open packages and require dependencies on test scope modules only for JUnit testing

与世无争的帅哥 提交于 2019-12-01 15:56:11
问题 I'm migrating a jar project from java 10 using classpath to java 11 using the java 9 jigsaw modules. There are JUnit5 tests for the project. The test dependencies are provided at test scope by maven. How to make all packages open for testing but not open when the module is used by another project? The jar project is just providing a few classes (like a utility project) for other projects (so no main class needed). The project got 5 packages at /src/main/java/a/b/c/ . 2 of them should be

NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.tryToLoadClass

半城伤御伤魂 提交于 2019-12-01 15:40:45
I have the test that leads to error. I tried to execute it in the IntelliJ Idea 2018.3.2 . All jupiter and junit dependencies have version RELEASE The full text of error: Dec 26, 2018 1:17:17 AM org.junit.platform.launcher.core.DefaultLauncher handleThrowable WARNING: TestEngine with ID 'junit-jupiter' failed to execute tests java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.tryToLoadClass(Ljava/lang/String;)Lorg/junit/platform/commons/function/Try; at org.junit.jupiter.engine.support.OpenTest4JAndJUnit4AwareThrowableCollector.createAbortedExecutionPredicate

Eclipse keep saying “No tests found with test runner JUnit 5”

杀马特。学长 韩版系。学妹 提交于 2019-12-01 06:24:05
I am using Eclipse Oxygen.3 Release (4.7.3). The following is my JUnit test class: import static org.junit.Assert.assertEquals; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; class MyMathTest { MyMath myMath = new MyMath(); @Before public void before() { System.out.println("Before"); } @After public void after() { System.out.println("After"); } @Test public void testSum_with3numbers() { System.out.println("Test1"); int result = myMath.sum(new int[] {1,2,3}); int expected = 6; assertEquals(expected, result); }

Gradle project running jUnit 5 tests in IntelliJ

落爺英雄遲暮 提交于 2019-12-01 03:02:57
I am trying both Gradle and jUnit5 right now. Everything works fine except that I cannot run a specific jUnit test. The "Run 'SampleTest'" option does not appear when I right-click a test class. I have the latest version of IntelliJ (2016.1.3) Ultimate. Here is my build.gradle file: repositories { mavenCentral() } apply plugin: 'java' version = '1.0.0-SNAPSHOT' jar { baseName = 'test-project' } dependencies { testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.0-M1' } The project structure is the standard one (like in Maven). And here is an example of a test:

Eclipse keep saying “No tests found with test runner JUnit 5”

浪子不回头ぞ 提交于 2019-12-01 02:09:33
问题 I am using Eclipse Oxygen.3 Release (4.7.3). The following is my JUnit test class: import static org.junit.Assert.assertEquals; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; class MyMathTest { MyMath myMath = new MyMath(); @Before public void before() { System.out.println("Before"); } @After public void after() { System.out.println("After"); } @Test public void testSum_with3numbers() { System.out.println(

Difference between junit-jupiter-api and junit-jupiter-engine

拟墨画扇 提交于 2019-12-01 02:06:56
What is difference between maven modules junit-jupiter-api and junit-jupiter-engine ? Is it necessary to include both dependencies in build.gradle ? Do I need to write both dependencies like testCompile("org.junit.jupiter:junit-jupiter-engine:${junitVersion}") testCompile("org.junit.jupiter:junit-jupiter-api:${junitVersion}") or testCompile("org.junit.jupiter:junit-jupiter-engine:${junitVersion}") is enough? And do I need to add dependency on junit-vintage-engine ? JUnit Prior to Version 5.4 From the docs : junit-jupiter-api JUnit Jupiter API for writing tests and extensions. junit-jupiter

What's the equivalent of org.junit.runner.JUnitCore.runClasses in Junit 5?

微笑、不失礼 提交于 2019-11-30 21:39:12
The following code started in JUnit4 and has been mostly translated into JUnit5 except for main() . The reason I'm writing it this way is that I'm demonstrating TDD and I have multiple versions of the StringInverter implementation, each of which implements more features and passes more tests. Here is the StringInverter interface: interface StringInverter { public String invert(String str); } And here's the almost-compiling-with-JUnit5 class: import java.util.*; import org.junit.jupiter.api.*; import static org.junit.jupiter.api.Assertions.*; import org.junit.platform.runner.JUnitPlatform;

How to launch JUnit 5 (Platform) from the command line (without Maven/Gradle)?

瘦欲@ 提交于 2019-11-30 20:55:29
I'd like to run a class containing JUnit 5 tests from the command line. Unfortunately, I have some outside dependencies that prevent me from using Maven, Gradle, or other build systems. In JUnit 4, I could accomplish this like java .:"lib/*" org.junit.runner.JUnitCore TestClass Is there an equivalent for JUnit 5? I'd simply like to know if test succeeded similar to when it runs in IntelliJ. TestClass.java import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.ArrayList; import

What's the equivalent of org.junit.runner.JUnitCore.runClasses in Junit 5?

与世无争的帅哥 提交于 2019-11-30 17:39:14
问题 The following code started in JUnit4 and has been mostly translated into JUnit5 except for main() . The reason I'm writing it this way is that I'm demonstrating TDD and I have multiple versions of the StringInverter implementation, each of which implements more features and passes more tests. Here is the StringInverter interface: interface StringInverter { public String invert(String str); } And here's the almost-compiling-with-JUnit5 class: import java.util.*; import org.junit.jupiter.api.*;