1

I found instructions on how to start a JUnit 4 test case from within Java, but have been unable to put together constructs that will fire up tests on a JUnit 5 test case.

The JUnit 4 solution I tried was this: How do I run JUnit tests from inside my java application?

I've been trying to get the ConsoleLauncher in JUnit5 to work, but it is throwing exceptions. That was documented here: http://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher

I'd like to automate starting tests to match running a program to simplify the instructions I'm providing when I provide unit tests to students.

Thanks!

argoc
  • 333
  • 1
  • 11
  • did u try that line: `import org.junit.Test;`? ,also i think Every test method in JUnit must be annotated with the @Test , **example :** `import org.junit.Test; public class VintageTest { @Test public static void main(String args[]) { org.junit.runner.JUnitCore.main("junitfaq.SimpleTest"); } @Test void test() { assertEquals("key", pair.getKey()); assertEquals("val", pair.getValue()); } }` . – The Doctor Dec 09 '17 at 23:18
  • Thanks, I will give that a try as well as looking into Maven or Gradle. – argoc Dec 11 '17 at 04:34

1 Answers1

1

If the goal is to simplify a task for students, I think it would be good to use a build tool like Maven or Gradle. This makes it simple to run tests, build their code, etc. JUnit5 tests can be run by using plugins - http://junit.org/junit5/docs/current/user-guide/#running-tests-build.

pablochan
  • 5,625
  • 27
  • 42
  • Agreed. The students need to have some exposure to build tools. And by the sounds of it, so does the OP. – Stephen C Dec 10 '17 at 02:37