Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testexecutors #6

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

package org.junit.gen5.commons.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Optional;

/**
* @author Stefan Bechtold
Expand Down Expand Up @@ -42,4 +45,18 @@ public static Object invokeMethod(Method method, Object testInstance)
return method.invoke(testInstance);
}

public static <A extends Annotation> Optional<A> getAnnotationFrom(AnnotatedElement element, Class<A> annotation) {
return Optional.ofNullable(element.getAnnotation(annotation));
}

public static Class<?> loadClass(String name) {
try {
// TODO Use correct classloader
// TODO Add support for primitive types and arrays.
return ClassLoader.getSystemClassLoader().loadClass(name);
}
catch (ClassNotFoundException e) {
throw new IllegalStateException("Failed to load class with name '" + name + "'.", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author Sam Brannen
* @since 5.0
*/
public class ColoredPrintingTestListener implements TestPlanExecutionListener, TestExecutionListener {
public class ColoredPrintingTestListener implements TestPlanExecutionListener {

private final PrintStream out;

Expand All @@ -39,26 +39,27 @@ public void testPlanExecutionStarted(TestPlan testPlan) {
}

@Override
public void testPlanExecutionPaused() {
public void testPlanExecutionPaused(TestPlan testPlan) {
out.println("Test execution paused.");
}

@Override
public void testPlanExecutionRestarted() {
public void testPlanExecutionRestarted(TestPlan testPlan) {
out.println("Test execution continued.");
}

@Override
public void testPlanExecutionStopped() {
public void testPlanExecutionStopped(TestPlan testPlan) {
out.println("Test execution canceled.");
}

@Override
public void testPlanExecutionFinished() {
public void testPlanExecutionFinished(TestPlan testPlan) {
out.println("Test execution finished.");
}

@Override
public void dynamicTestFound(TestDescriptor testDescriptor) {
public void testFound(TestDescriptor testDescriptor) {
printlnTestDescriptor(BLUE, "Test found:", testDescriptor);
}

Expand Down Expand Up @@ -104,7 +105,6 @@ void println(Color color, String format, Object... args) {
}

static enum Color {

NONE("\u001B[0m"),

BLACK("\u001B[30m"),
Expand Down Expand Up @@ -134,5 +134,4 @@ public String toString() {
return this.ansiCode;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
public class ConsoleRunner {

public static void main(String... args) {

// TODO Configure launcher?
Launcher launcher = new Launcher();

launcher.registerTestPlanExecutionListeners(
launcher.registerListeners(
// @formatter:off
new ColoredPrintingTestListener(System.out),
new TestSummaryReportingTestListener(System.out)
// @formatter:on
new ColoredPrintingTestListener(System.out),
new TestSummaryReportingTestListener(System.out)
// @formatter:on
);

TestPlanSpecification testPlanSpecification = TestPlanSpecification.build(
Expand All @@ -38,5 +36,4 @@ public static void main(String... args) {
// TODO Provide means to allow manipulation of test plan?
launcher.execute(testPlanSpecification);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author Sam Brannen
* @since 5.0
*/
public class TestSummaryReportingTestListener implements TestPlanExecutionListener, TestExecutionListener {
public class TestSummaryReportingTestListener implements TestPlanExecutionListener {

private final PrintStream out;

Expand All @@ -49,23 +49,23 @@ public void testPlanExecutionStarted(TestPlan testPlan) {
}

@Override
public void testPlanExecutionPaused() {
public void testPlanExecutionPaused(TestPlan testPlan) {
this.timePaused = System.currentTimeMillis();
}

@Override
public void testPlanExecutionRestarted() {
public void testPlanExecutionRestarted(TestPlan testPlan) {
this.timeStarted += System.currentTimeMillis() - this.timePaused;
this.timePaused = 0;
}

@Override
public void testPlanExecutionStopped() {
public void testPlanExecutionStopped(TestPlan testPlan) {
reportSummary("Test run stopped");
}

@Override
public void testPlanExecutionFinished() {
public void testPlanExecutionFinished(TestPlan testPlan) {
reportSummary("Test run finished");
}

Expand All @@ -87,7 +87,7 @@ private void reportSummary(String msg) {
}

@Override
public void dynamicTestFound(TestDescriptor testDescriptor) {
public void testFound(TestDescriptor testDescriptor) {
this.testsFound.incrementAndGet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
public class ClassNameSpecification implements TestPlanSpecificationElement {

private String className;

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

/**
* @author Sam Brannen
* @author Stefan Bechtold
* @since 5.0
*/
public interface TestDescriptor {
Expand All @@ -21,23 +22,12 @@ public interface TestDescriptor {
*
* <p>Uniqueness must be guaranteed across an entire test plan,
* regardless of how many engines are used behind the scenes.
*
* <p>The ID is simply the concatenation of the {@linkplain #getEngineId engine ID}
* and the {@linkplain #getTestId test ID} separated by a colon ({@code ":"})
* &mdash; for example, {@code myEngine:test-description-unique-within-my-engine}.
*/
default String getUniqueId() {
return String.format("%s:%s", getEngineId(), getTestId());
};

String getEngineId();

String getTestId();
String getUniqueId();

String getDisplayName();

TestDescriptor getParent();

boolean isTest();

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ default String getId() {
return getClass().getCanonicalName();
}

Collection<TestDescriptor> discoverTests(TestPlanSpecification specification, TestDescriptor root);
Collection<TestDescriptor> discoverTests(TestPlanSpecification specification);

default boolean supports(TestDescriptor testDescriptor) {
return testDescriptor.getUniqueId().startsWith(getId());
Expand All @@ -28,10 +28,5 @@ default boolean supportsAll(Collection<TestDescriptor> testDescriptors) {
return testDescriptors.stream().allMatch(testDescriptor -> supports(testDescriptor));
}

default TestDescriptor createEngineDescriptor() {
return new EngineDescriptor(getId());
}

void execute(Collection<TestDescriptor> testDescriptions, TestExecutionListener testExecutionListener);

void execute(TestExecutionContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2015 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.junit.gen5.engine;

import java.util.Collection;

import lombok.Value;

/**
* @author Stefan Bechtold
* @since 5.0
*/
@Value
public class TestExecutionContext {

private Collection<TestDescriptor> testDescriptors;
private TestExecutionListener testExecutionListener;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
*/
public interface TestExecutionListener {

default void dynamicTestFound(TestDescriptor testDescriptor) {
};
default void testFound(TestDescriptor testDescriptor) {
}

default void testStarted(TestDescriptor testDescriptor) {
};
}

default void testSkipped(TestDescriptor testDescriptor, Throwable t) {
};
}

default void testAborted(TestDescriptor testDescriptor, Throwable t) {
};
}

default void testFailed(TestDescriptor testDescriptor, Throwable t) {
};
}

default void testSucceeded(TestDescriptor testDescriptor) {
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2015 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.junit.gen5.engine;

/**
* @author Stefan Bechtold
* @author Sam Brannen
* @author Matthias Merdes
* @since 5.0
*/
public interface TestExecutor {

void execute(TestExecutionContext context);

boolean isRoot();
}
Loading