@SelectClasses specifies the classes to select when running a test suite on the JUnit Platform.
Example
@RunWith(JUnitPlatform.class)
@SuiteDisplayName("JUnit Platform Suite Demo")
@SelectClasses({ DummyTest.class, ArithmeticTest.class })
public class SelectClassesDemo1 {
}
Find the below working application.
ArithmeticTest.java
package com.sample.app.arithmetic;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class ArithmeticTest {
private static int sum(int a, int b) {
return a + b;
}
@Test
public void test1() {
assertEquals(5, sum(2, 3));
}
}
DummyTest.java
package com.sample.app.dummy;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
public class DummyTest {
@Test
public void test1() {
assertTrue(true);
}
}
SelectClassesDemo1.java
package com.sample.app.suite;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.SuiteDisplayName;
import org.junit.runner.RunWith;
import com.sample.app.arithmetic.ArithmeticTest;
import com.sample.app.dummy.DummyTest;
@RunWith(JUnitPlatform.class)
@SuiteDisplayName("JUnit Platform Suite Demo")
@SelectClasses({ DummyTest.class, ArithmeticTest.class })
public class SelectClassesDemo1 {
}
Run the test class ‘SelectClassesDemo1’, you can observe that the tests in the classes DummyTest and ArithmeticTest gets executed.
No comments:
Post a Comment