Maybe this is very simple, but I couldn\'t find any examples on the web:
I\'d like to use JUnit 5 to run a unit test implemented as a Groovy class. My current setup
JUnit requires all testing method to use return type void. Groovy's def keyword is compiled to an Object type, so your method compiles to something like this in Java:
import org.junit.jupiter.api.Test
public class UnitTest {
@Test
Object shouldDoStuff() {
throw new RuntimeException();
}
}
If you try this out as a Java test, it won't find the test case neither. The solution is very simple - replace def with void and your Groovy
test case will be executed correctly.
src/test/groovy/UnitTest.groovy
import org.junit.jupiter.api.Test
class UnitTest {
@Test
void shouldDoStuff() {
throw new RuntimeException()
}
}
Demo: