Search in sources :

Example 76 with Description

use of org.junit.runner.Description in project junit-dataprovider by TNG.

the class DataProviderFilterTest method testShouldRunShouldReturnTrueForMultipleChildDescriptionWithLastMatching.

@Test
public void testShouldRunShouldReturnTrueForMultipleChildDescriptionWithLastMatching() {
    // Given:
    doReturn("Method testMain[1: ](com.tngtech.Clazz)").when(filter).describe();
    // @formatter:off
    Description description = setupDescription(false, "", setupDescription(true, "testOther[1: ](com.tngtech.ClazzOther)"), setupDescription(false, "testOther[1: ](com.tngtech.ClazzOther)"), setupDescription(true, "testMain[1: ](com.tngtech.Clazz)"));
    // @formatter:on
    // When:
    boolean result = underTest.shouldRun(description);
    // Then:
    assertThat(result).isTrue();
}
Also used : Description(org.junit.runner.Description) Test(org.junit.Test)

Example 77 with Description

use of org.junit.runner.Description in project junit-dataprovider by TNG.

the class DataProviderFilterTest method testShouldRunShouldReturnFalseWhenDescriptionDoesNotHaveExpectedPackageName.

@Test
public void testShouldRunShouldReturnFalseWhenDescriptionDoesNotHaveExpectedPackageName() {
    // Given:
    doReturn("Method testMain[1: ](com.tngtech.Clazz)").when(filter).describe();
    Description description = setupDescription(true, "testMain[1: ](com.tngtech.other.Clazz)");
    // When:
    boolean result = underTest.shouldRun(description);
    // Then:
    assertThat(result).isFalse();
}
Also used : Description(org.junit.runner.Description) Test(org.junit.Test)

Example 78 with Description

use of org.junit.runner.Description in project statecharts by Yakindu.

the class GTestRunner method getDescription.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.junit.runner.Runner#getDescription()
	 */
@Override
public Description getDescription() {
    Description description = Description.createSuiteDescription(testClass);
    for (Entry<String, List<String>> entry : testCases.entrySet()) {
        for (String test : entry.getValue()) {
            String testCase = entry.getKey();
            Description childDescription = createDescription(testCase, test);
            description.addChild(childDescription);
        }
    }
    return description;
}
Also used : Description(org.junit.runner.Description) ArrayList(java.util.ArrayList) List(java.util.List)

Example 79 with Description

use of org.junit.runner.Description in project statecharts by Yakindu.

the class GTestRunner method runGTests.

private void runGTests(RunNotifier notifier) throws IOException, InterruptedException {
    String program = testClass.getAnnotation(GTest.class).program();
    if (Platform.getOS().equalsIgnoreCase(Platform.OS_WIN32)) {
        program += ".exe";
    }
    String targetProject = testClass.getAnnotation(GTest.class).testBundle();
    IPath programPath = new Path(targetProject).append(program);
    IResource programFile = ResourcesPlugin.getWorkspace().getRoot().findMember(programPath);
    IContainer programContainer = programFile.getParent();
    if (!programContainer.isAccessible()) {
        throw new RuntimeException("Test program container " + programContainer.getLocation().toOSString() + " inaccessible");
    }
    File directory = programContainer.getLocation().toFile();
    Process process = new ProcessBuilder(programFile.getLocation().toOSString()).redirectErrorStream(true).directory(directory).start();
    BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    boolean started = false;
    boolean running = false;
    StringBuilder message = new StringBuilder();
    String line;
    while ((line = reader.readLine()) != null) {
        if (line.startsWith("[====")) {
            if (started) {
                started = false;
                // Eat remaining input
                char[] buffer = new char[4096];
                while (reader.read(buffer) != -1) ;
                break;
            }
            started = true;
        } else {
            TestOutput testOutput = parseTestOutput(line);
            if (testOutput != null) {
                Description description = testOutput.toDescription();
                switch(testOutput.getStatus()) {
                    case TestOutput.RUN:
                        running = true;
                        message.setLength(0);
                        notifier.fireTestStarted(description);
                        break;
                    case TestOutput.OK:
                        running = false;
                        notifier.fireTestFinished(description);
                        break;
                    default:
                        running = false;
                        notifier.fireTestFailure(new Failure(description, new AssertionFailedError(message.toString())));
                        notifier.fireTestFinished(description);
                        break;
                }
            } else if (running) {
                message.append(line);
                message.append("\n");
            }
        }
    }
    process.waitFor();
    if (started) {
        throw new RuntimeException("Test quit unexpectedly (exit status " + process.exitValue() + "):\n" + message);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Description(org.junit.runner.Description) IPath(org.eclipse.core.runtime.IPath) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IContainer(org.eclipse.core.resources.IContainer) AssertionFailedError(junit.framework.AssertionFailedError) File(java.io.File) IResource(org.eclipse.core.resources.IResource) Failure(org.junit.runner.notification.Failure)

Example 80 with Description

use of org.junit.runner.Description in project tests by datanucleus.

the class DataNucleusTestWatcher method filterDatastores.

private void filterDatastores(Class<?> testClass) {
    List<DatastoreKey> filterDatastores = findAnnotationAtMethodOrClass(Datastore.class, description, testClass).map(annotation -> asList(annotation.value())).orElse(emptyList());
    if (!filterDatastores.isEmpty()) {
        String datastoreKey = JDOPersistenceTestCase.storeMgr.getStoreManagerKey();
        DatastoreKey currentDatastore = DatastoreKey.valueOf(datastoreKey.toUpperCase());
        DatastoreKey vendorIdDatastore = JDOPersistenceTestCase.vendorID == null ? null : DatastoreKey.valueOf(JDOPersistenceTestCase.vendorID.toUpperCase());
        Assume.assumeTrue(filterDatastores.stream().anyMatch(filter -> filter.equals(currentDatastore) || filter.equals(vendorIdDatastore)));
    }
}
Also used : Datastore(org.datanucleus.tests.annotations.Datastore) Collections.emptyList(java.util.Collections.emptyList) Description(org.junit.runner.Description) AssertionFailedError(junit.framework.AssertionFailedError) Mode(org.datanucleus.tests.annotations.TransactionMode.Mode) TestWatcher(org.junit.rules.TestWatcher) List(java.util.List) NucleusLogger(org.datanucleus.util.NucleusLogger) Arrays.asList(java.util.Arrays.asList) OPTIMISTIC(org.datanucleus.tests.annotations.TransactionMode.Mode.OPTIMISTIC) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) DatastoreKey(org.datanucleus.tests.annotations.Datastore.DatastoreKey) Assume(org.junit.Assume) PESSIMISTIC(org.datanucleus.tests.annotations.TransactionMode.Mode.PESSIMISTIC) TransactionMode(org.datanucleus.tests.annotations.TransactionMode) DatastoreKey(org.datanucleus.tests.annotations.Datastore.DatastoreKey)

Aggregations

Description (org.junit.runner.Description)309 Test (org.junit.Test)119 Failure (org.junit.runner.notification.Failure)57 Result (org.junit.runner.Result)32 ArrayList (java.util.ArrayList)25 RunListener (org.junit.runner.notification.RunListener)23 IOException (java.io.IOException)22 Request (org.junit.runner.Request)21 Method (java.lang.reflect.Method)18 JUnitCore (org.junit.runner.JUnitCore)17 Test (org.junit.jupiter.api.Test)14 Filter (org.junit.runner.manipulation.Filter)14 File (java.io.File)13 Runner (org.junit.runner.Runner)13 Statement (org.junit.runners.model.Statement)13 LoggingListener (org.elasticsearch.test.junit.listeners.LoggingListener)12 RunNotifier (org.junit.runner.notification.RunNotifier)12 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)10 ComparisonFailure (org.junit.ComparisonFailure)10 Description.createTestDescription (org.junit.runner.Description.createTestDescription)9