use of cucumber.runtime.Runtime in project cucumber-jvm by cucumber.
the class CalculatorTest method cucumber.
@Test
public void cucumber() throws Exception {
assertNotNull(injector);
assertNotNull(bundleContext);
final ResourceLoader resourceLoader = new FileResourceLoader();
final ClassLoader classLoader = Runtime.class.getClassLoader();
final ObjectFactory objectFactory = new PaxExamObjectFactory(injector);
final ClassFinder classFinder = new OsgiClassFinder(bundleContext);
final Backend backend = new JavaBackend(objectFactory, classFinder);
final RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(getClass());
final RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
final Runtime runtime = new Runtime(resourceLoader, classLoader, Collections.singleton(backend), runtimeOptions);
runtime.run();
if (!runtime.getErrors().isEmpty()) {
throw new CucumberException(runtime.getErrors().get(0));
} else if (runtime.exitStatus() != 0x00) {
throw new CucumberException("There are pending or undefined steps.");
}
assertEquals(runtime.getErrors().size(), 0);
}
use of cucumber.runtime.Runtime in project cucumber-jvm by cucumber.
the class JUnitFormatterTest method runFeaturesWithJunitFormatter.
private File runFeaturesWithJunitFormatter(final List<String> featurePaths, boolean strict) throws IOException {
File report = File.createTempFile("cucumber-jvm-junit", "xml");
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
List<String> args = new ArrayList<String>();
if (strict) {
args.add("--strict");
}
args.add("--plugin");
args.add("junit:" + report.getAbsolutePath());
args.addAll(featurePaths);
RuntimeOptions runtimeOptions = new RuntimeOptions(args);
Backend backend = mock(Backend.class);
when(backend.getSnippet(any(Step.class), any(FunctionNameGenerator.class))).thenReturn("TEST SNIPPET");
final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, classLoader, asList(backend), runtimeOptions);
runtime.run();
return report;
}
use of cucumber.runtime.Runtime in project intellij-community by JetBrains.
the class CucumberMain method run.
public static int run(final String[] argv, final ClassLoader classLoader) throws IOException {
final Ref<Throwable> errorRef = new Ref<>();
final Ref<Runtime> runtimeRef = new Ref<>();
try {
TestRunnerUtil.replaceIdeEventQueueSafely();
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
try {
RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList(Arrays.asList(argv)));
MultiLoader resourceLoader = new MultiLoader(classLoader);
ResourceLoaderClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
runtimeRef.set(runtime);
runtime.run();
} catch (Throwable throwable) {
errorRef.set(throwable);
Logger.getInstance(CucumberMain.class).error(throwable);
}
}
});
} catch (Throwable t) {
errorRef.set(t);
Logger.getInstance(CucumberMain.class).error(t);
}
final Throwable throwable = errorRef.get();
if (throwable != null) {
throwable.printStackTrace();
}
System.err.println("Failed tests :");
for (Throwable error : runtimeRef.get().getErrors()) {
error.printStackTrace();
System.err.println("=============================");
}
return throwable != null ? 1 : 0;
}
use of cucumber.runtime.Runtime in project cucumber-jvm by cucumber.
the class Main method run.
/**
* Launches the Cucumber-JVM command line.
*
* @param argv runtime options. See details in the {@code cucumber.api.cli.Usage.txt} resource.
* @param classLoader classloader used to load the runtime
* @return 0 if execution was successful, 1 if it was not (test failures)
* @throws IOException if resources couldn't be loaded during the run.
*/
public static byte run(String[] argv, ClassLoader classLoader) throws IOException {
RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList<String>(asList(argv)));
ResourceLoader resourceLoader = new MultiLoader(classLoader);
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
runtime.run();
return runtime.exitStatus();
}
use of cucumber.runtime.Runtime in project cucumber-jvm by cucumber.
the class FeatureRunnerTest method runFeatureWithFormatterSpy.
private String runFeatureWithFormatterSpy(CucumberFeature cucumberFeature) throws InitializationError {
final RuntimeOptions runtimeOptions = new RuntimeOptions("");
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
final RuntimeGlue glue = mock(RuntimeGlue.class);
final Runtime runtime = new Runtime(resourceLoader, classLoader, asList(mock(Backend.class)), runtimeOptions, new StopWatch.Stub(0l), glue);
FormatterSpy formatterSpy = new FormatterSpy();
FeatureRunner runner = new FeatureRunner(cucumberFeature, runtime, new JUnitReporter(formatterSpy, formatterSpy, false, new JUnitOptions(Collections.<String>emptyList())));
runner.run(mock(RunNotifier.class));
return formatterSpy.toString();
}
Aggregations