Skip to content

Commit

Permalink
Exclude tests where TestPlan is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Nov 24, 2015
1 parent d20d0a6 commit 1fcc502
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 36 deletions.

This file was deleted.

Expand Up @@ -48,21 +48,27 @@ public RunResult invoke(Object forkTestSet)
throw new UnsupportedOperationException("Not yet supported."); throw new UnsupportedOperationException("Not yet supported.");
} }


TestsToRun testsToRun = scanClasspath(); Launcher launcher = new Launcher();
return invoke(testsToRun); TestsToRun testsToRun = scanClasspath(launcher);
return invokeAllTests(testsToRun, launcher);
} }


private RunResult invoke(TestsToRun testsToRun) { private TestsToRun scanClasspath(Launcher launcher) {
TestsToRun scannedClasses = parameters.getScanResult().applyFilter(new TestPlanScannerFilter(launcher),
parameters.getTestClassLoader());
TestsToRun orderedClasses = parameters.getRunOrderCalculator().orderTestClasses(scannedClasses);
return orderedClasses;
}

private RunResult invokeAllTests(TestsToRun testsToRun, Launcher launcher) {
RunResult runResult; RunResult runResult;
ReporterFactory reporterFactory = parameters.getReporterFactory(); ReporterFactory reporterFactory = parameters.getReporterFactory();
try { try {
RunListener runListener = reporterFactory.createReporter(); RunListener runListener = reporterFactory.createReporter();

Launcher launcher = new Launcher();
launcher.registerTestPlanExecutionListeners(new RunListenerAdapter(runListener)); launcher.registerTestPlanExecutionListeners(new RunListenerAdapter(runListener));


for (Class<?> testClass : testsToRun) { for (Class<?> testClass : testsToRun) {
invoke(testClass, launcher, runListener); invokeSingleClass(testClass, launcher, runListener);
} }
} }
finally { finally {
Expand All @@ -71,14 +77,7 @@ private RunResult invoke(TestsToRun testsToRun) {
return runResult; return runResult;
} }


private TestsToRun scanClasspath() { private void invokeSingleClass(Class<?> testClass, Launcher launcher, RunListener runListener) {
TestsToRun scannedClasses = parameters.getScanResult().applyFilter(new AcceptAllClassesScannerFilter(),
parameters.getTestClassLoader());
TestsToRun orderedClasses = parameters.getRunOrderCalculator().orderTestClasses(scannedClasses);
return orderedClasses;
}

private void invoke(Class<?> testClass, Launcher launcher, RunListener runListener) {
SimpleReportEntry classEntry = new SimpleReportEntry(getClass().getName(), testClass.getName()); SimpleReportEntry classEntry = new SimpleReportEntry(getClass().getName(), testClass.getName());
runListener.testSetStarting(classEntry); runListener.testSetStarting(classEntry);


Expand Down
@@ -0,0 +1,35 @@
/*
* 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.surefire;

import static org.junit.gen5.engine.TestPlanSpecification.build;

import org.apache.maven.surefire.util.ScannerFilter;
import org.junit.gen5.engine.TestPlanSpecification;
import org.junit.gen5.launcher.Launcher;
import org.junit.gen5.launcher.TestPlan;

final class TestPlanScannerFilter implements ScannerFilter {

private final Launcher launcher;

public TestPlanScannerFilter(Launcher launcher) {
this.launcher = launcher;
}

@SuppressWarnings("rawtypes")
@Override
public boolean accept(Class testClass) {
TestPlanSpecification specification = build(TestPlanSpecification.forClass(testClass));
TestPlan testPlan = launcher.discover(specification);
return testPlan.hasTests();
}
}

0 comments on commit 1fcc502

Please sign in to comment.