import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @RunWith(JUnitPlatform.class) public class UmsServiceTest { @BeforeEach public void setUp() { } @Test public void getPrefixUsernames() { assertThat(UmsService.getPrefixedUsername("msun", STAFF), is("user:msun")); assertThat(UmsService.getPrefixedUsername("msun", PUBLIC_USER), is("user:public:msun")); } }
Upon running it (by right clicking on the test and 'Run as' -> JUnit test, I get this error.
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=getPrefixUsernames], {ExactMatcher:fDisplayName=getPrefixUsernames(au.gov.nla.ums.keycloak.service.UmsServiceTest)], {LeadingIdentifierMatcher:fClassName=au.gov.nla.ums.keycloak.service.UmsServiceTest,fLeadingIdentifier=getPrefixUsernames]] from org.junit.internal.requests.ClassRequest@77ec78b9 at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:80) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:71) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
This is because I have created this class as JUnit 4 class in Eclipse.
And now I am trying to run it as JUnit 5 test case.
To fix this, I need to change the test runner to JUnit 5 by right clicking on the test -> 'Run as' -> Run Configurations, and selecting 'JUnit 5' as the tester runner
helpul
ReplyDelete