Search in sources :

Example 1 with Tests

use of com.oracle.bedrock.testsupport.junit.options.Tests in project oracle-bedrock by coherence-community.

the class JUnitTestRunner method runTests.

/**
 * Run the tests specified by the given {@link OptionsByType}.
 *
 * @param optionsByType  the {@link OptionsByType} controlling the test run
 */
private void runTests(OptionsByType optionsByType) {
    // If the options are null there is nothing to do
    if (optionsByType == null) {
        return;
    }
    Tests tests = optionsByType.get(Tests.class);
    // If there are no tests to execute then return
    if (tests.isEmpty()) {
        return;
    }
    JUnitCore jUnitCore = new JUnitCore();
    Result result = new Result();
    Listener listener = new Listener();
    jUnitCore.addListener(result.createListener());
    jUnitCore.addListener(listener);
    for (RunListener runListener : optionsByType.getInstancesOf(RunListener.class)) {
        jUnitCore.addListener(runListener);
    }
    // Run the tests in each TestClasses instance
    for (TestClasses testClasses : tests) {
        Set<Class<?>> classes = testClasses.resolveTestClasses();
        Filter filter = testClasses.getTestFilter();
        for (Class<?> testClass : classes) {
            Request request = Request.aClass(testClass);
            if (filter != null) {
                request = request.filterWith(filter);
            }
            jUnitCore.run(request);
            // If the state has changed to stopped then we should exit
            if (state == State.Stopped) {
                return;
            }
        }
    }
}
Also used : TestClasses(com.oracle.bedrock.testsupport.junit.options.TestClasses) RunListener(org.junit.runner.notification.RunListener) JUnitCore(org.junit.runner.JUnitCore) Filter(org.junit.runner.manipulation.Filter) Request(org.junit.runner.Request) Tests(com.oracle.bedrock.testsupport.junit.options.Tests) Result(org.junit.runner.Result) RunListener(org.junit.runner.notification.RunListener)

Example 2 with Tests

use of com.oracle.bedrock.testsupport.junit.options.Tests in project oracle-bedrock by coherence-community.

the class TestsTest method shouldWorkAsAnOption.

@Test
public void shouldWorkAsAnOption() throws Exception {
    TestClasses tests = TestClasses.of(JUnit4Test.class);
    OptionsByType optionsByType = OptionsByType.of(tests);
    Tests result = optionsByType.get(Tests.class);
    assertThat(result, is(notNullValue()));
    assertThat(result, contains(tests));
}
Also used : TestClasses(com.oracle.bedrock.testsupport.junit.options.TestClasses) OptionsByType(com.oracle.bedrock.OptionsByType) Tests(com.oracle.bedrock.testsupport.junit.options.Tests) MyOtherTest(com.oracle.bedrock.testsupport.junit.MyOtherTest) JUnit4Test(com.oracle.bedrock.testsupport.junit.JUnit4Test) Test(org.junit.Test)

Example 3 with Tests

use of com.oracle.bedrock.testsupport.junit.options.Tests in project oracle-bedrock by coherence-community.

the class TestsTest method shouldAddMultipleSpecifiedTestClasses.

@Test
public void shouldAddMultipleSpecifiedTestClasses() throws Exception {
    TestClasses first = TestClasses.of(JUnit4Test.class);
    TestClasses second = TestClasses.of(MyOtherTest.class);
    OptionsByType optionsByType = OptionsByType.of(first, second);
    Tests result = optionsByType.get(Tests.class);
    assertThat(result, is(notNullValue()));
    assertThat(result, contains(first, second));
}
Also used : TestClasses(com.oracle.bedrock.testsupport.junit.options.TestClasses) OptionsByType(com.oracle.bedrock.OptionsByType) Tests(com.oracle.bedrock.testsupport.junit.options.Tests) MyOtherTest(com.oracle.bedrock.testsupport.junit.MyOtherTest) JUnit4Test(com.oracle.bedrock.testsupport.junit.JUnit4Test) Test(org.junit.Test)

Example 4 with Tests

use of com.oracle.bedrock.testsupport.junit.options.Tests in project oracle-bedrock by coherence-community.

the class TestsTest method shouldRemoveSpecificTestClass.

@Test
public void shouldRemoveSpecificTestClass() throws Exception {
    TestClasses first = TestClasses.of(JUnit4Test.class);
    TestClasses second = TestClasses.of(MyOtherTest.class);
    OptionsByType optionsByType = OptionsByType.of(first, second);
    optionsByType.remove(TestClasses.of(JUnit4Test.class));
    Tests result = optionsByType.get(Tests.class);
    assertThat(result, is(notNullValue()));
    assertThat(result, contains(second));
}
Also used : TestClasses(com.oracle.bedrock.testsupport.junit.options.TestClasses) JUnit4Test(com.oracle.bedrock.testsupport.junit.JUnit4Test) OptionsByType(com.oracle.bedrock.OptionsByType) Tests(com.oracle.bedrock.testsupport.junit.options.Tests) MyOtherTest(com.oracle.bedrock.testsupport.junit.MyOtherTest) JUnit4Test(com.oracle.bedrock.testsupport.junit.JUnit4Test) Test(org.junit.Test)

Example 5 with Tests

use of com.oracle.bedrock.testsupport.junit.options.Tests in project oracle-bedrock by coherence-community.

the class TestsTest method shouldHaveEmptyTestsAsDefaultOption.

@Test
public void shouldHaveEmptyTestsAsDefaultOption() throws Exception {
    OptionsByType optionsByType = OptionsByType.empty();
    Tests result = optionsByType.get(Tests.class);
    assertThat(result, is(notNullValue()));
    assertThat(result.iterator().hasNext(), is(false));
}
Also used : OptionsByType(com.oracle.bedrock.OptionsByType) Tests(com.oracle.bedrock.testsupport.junit.options.Tests) MyOtherTest(com.oracle.bedrock.testsupport.junit.MyOtherTest) JUnit4Test(com.oracle.bedrock.testsupport.junit.JUnit4Test) Test(org.junit.Test)

Aggregations

Tests (com.oracle.bedrock.testsupport.junit.options.Tests)5 OptionsByType (com.oracle.bedrock.OptionsByType)4 JUnit4Test (com.oracle.bedrock.testsupport.junit.JUnit4Test)4 MyOtherTest (com.oracle.bedrock.testsupport.junit.MyOtherTest)4 TestClasses (com.oracle.bedrock.testsupport.junit.options.TestClasses)4 Test (org.junit.Test)4 JUnitCore (org.junit.runner.JUnitCore)1 Request (org.junit.runner.Request)1 Result (org.junit.runner.Result)1 Filter (org.junit.runner.manipulation.Filter)1 RunListener (org.junit.runner.notification.RunListener)1