Search in sources :

Example 1 with MethodSource

use of org.junit.platform.engine.support.descriptor.MethodSource in project junit5 by junit-team.

the class VintageTestEngineDiscoveryTests method assertMethodSource.

private static void assertMethodSource(Method expectedMethod, TestDescriptor testDescriptor) {
    assertThat(testDescriptor.getSource()).containsInstanceOf(MethodSource.class);
    MethodSource methodSource = (MethodSource) testDescriptor.getSource().get();
    assertThat(methodSource.getClassName()).isEqualTo(expectedMethod.getDeclaringClass().getName());
    assertThat(methodSource.getMethodName()).isEqualTo(expectedMethod.getName());
    assertThat(methodSource.getMethodParameterTypes()).isEqualTo(ClassUtils.nullSafeToString(expectedMethod.getParameterTypes()));
}
Also used : MethodSource(org.junit.platform.engine.support.descriptor.MethodSource)

Example 2 with MethodSource

use of org.junit.platform.engine.support.descriptor.MethodSource in project intellij-community by JetBrains.

the class JUnit5TestExecutionListener method getLocationHintValue.

static String getLocationHintValue(TestSource testSource, boolean isTest) {
    if (testSource instanceof CompositeTestSource) {
        CompositeTestSource compositeTestSource = ((CompositeTestSource) testSource);
        for (TestSource sourceFromComposite : compositeTestSource.getSources()) {
            String locationHintValue = getLocationHintValue(sourceFromComposite, isTest);
            if (!NO_LOCATION_HINT_VALUE.equals(locationHintValue)) {
                return locationHintValue;
            }
        }
        return NO_LOCATION_HINT_VALUE;
    }
    if (testSource instanceof FileSource) {
        FileSource fileSource = (FileSource) testSource;
        File file = fileSource.getFile();
        String line = fileSource.getPosition().map(position -> ":" + position.getLine()).orElse("");
        return "file://" + file.getAbsolutePath() + line;
    }
    if (testSource instanceof MethodSource) {
        MethodSource methodSource = (MethodSource) testSource;
        return javaLocation(methodSource.getClassName(), methodSource.getMethodName(), isTest);
    }
    if (testSource instanceof ClassSource) {
        String className = ((ClassSource) testSource).getClassName();
        return javaLocation(className, null, isTest);
    }
    return NO_LOCATION_HINT_VALUE;
}
Also used : ReportEntry(org.junit.platform.engine.reporting.ReportEntry) TestPlan(org.junit.platform.launcher.TestPlan) JUnit4TestListener(com.intellij.junit4.JUnit4TestListener) CompositeTestSource(org.junit.platform.engine.support.descriptor.CompositeTestSource) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) ClassSource(org.junit.platform.engine.support.descriptor.ClassSource) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) AssertionFailedError(org.opentest4j.AssertionFailedError) Map(java.util.Map) ExpectedPatterns(com.intellij.junit4.ExpectedPatterns) MapSerializerUtil(com.intellij.rt.execution.junit.MapSerializerUtil) MethodSource(org.junit.platform.engine.support.descriptor.MethodSource) PrintStream(java.io.PrintStream) PrintWriter(java.io.PrintWriter) ComparisonFailureData(com.intellij.rt.execution.junit.ComparisonFailureData) FileSource(org.junit.platform.engine.support.descriptor.FileSource) MultipleFailuresError(org.opentest4j.MultipleFailuresError) StringWriter(java.io.StringWriter) TestSource(org.junit.platform.engine.TestSource) Set(java.util.Set) File(java.io.File) TestIdentifier(org.junit.platform.launcher.TestIdentifier) ValueWrapper(org.opentest4j.ValueWrapper) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) CompositeTestSource(org.junit.platform.engine.support.descriptor.CompositeTestSource) CompositeTestSource(org.junit.platform.engine.support.descriptor.CompositeTestSource) TestSource(org.junit.platform.engine.TestSource) FileSource(org.junit.platform.engine.support.descriptor.FileSource) MethodSource(org.junit.platform.engine.support.descriptor.MethodSource) File(java.io.File) ClassSource(org.junit.platform.engine.support.descriptor.ClassSource)

Example 3 with MethodSource

use of org.junit.platform.engine.support.descriptor.MethodSource in project junit5 by junit-team.

the class DemoHierarchicalTestEngine method addTest.

public DemoHierarchicalTestDescriptor addTest(Method testMethod, Runnable executeBlock) {
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", testMethod.getName());
    MethodSource source = MethodSource.from(testMethod);
    DemoHierarchicalTestDescriptor child = new DemoHierarchicalTestDescriptor(uniqueId, testMethod.getName(), source, executeBlock);
    engineDescriptor.addChild(child);
    return child;
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) MethodSource(org.junit.platform.engine.support.descriptor.MethodSource)

Aggregations

MethodSource (org.junit.platform.engine.support.descriptor.MethodSource)3 ExpectedPatterns (com.intellij.junit4.ExpectedPatterns)1 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)1 ComparisonFailureData (com.intellij.rt.execution.junit.ComparisonFailureData)1 MapSerializerUtil (com.intellij.rt.execution.junit.MapSerializerUtil)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)1 TestSource (org.junit.platform.engine.TestSource)1 UniqueId (org.junit.platform.engine.UniqueId)1 ReportEntry (org.junit.platform.engine.reporting.ReportEntry)1 ClassSource (org.junit.platform.engine.support.descriptor.ClassSource)1 CompositeTestSource (org.junit.platform.engine.support.descriptor.CompositeTestSource)1 FileSource (org.junit.platform.engine.support.descriptor.FileSource)1