All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rest.RestExampleRunner Maven / Gradle / Ivy

Go to download

Rest Cucumber allows you to attach a rest client for retrieval of Cucumber feature files and posting of Cucumber test results

There is a newer version: 1.3
Show newest version
package rest;

import java.util.ArrayList;
import java.util.List;
import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.Suite;
import org.junit.runners.model.InitializationError;
import cucumber.runtime.junit.ExamplesRunner;
import cucumber.runtime.junit.ExecutionUnitRunner;
import cucumber.runtime.junit.JUnitReporter;
import cucumber.runtime.model.CucumberExamples;
import cucumber.runtime.model.CucumberFeature;
import cucumber.runtime.model.CucumberScenario;

public class RestExampleRunner extends Suite {
   private final CucumberExamples cucumberExamples;
   private Description description;
   private JUnitReporter jUnitReporter;

   protected RestExampleRunner(RestRuntime runtime, CucumberExamples cucumberExamples,
      RestJUnitReporter jUnitReporter, CucumberFeature cucumberFeature)
      throws InitializationError {
      super(ExamplesRunner.class, buildRunners(runtime, cucumberExamples, jUnitReporter,
         cucumberFeature));
      this.cucumberExamples = cucumberExamples;
      this.jUnitReporter = jUnitReporter;
   }

   private static List buildRunners(RestRuntime runtime,
      CucumberExamples cucumberExamples, RestJUnitReporter jUnitReporter,
      CucumberFeature cucumberFeature) {
      List runners = new ArrayList();
      List exampleScenarios = cucumberExamples.createExampleScenarios();
      for (CucumberScenario scenario : exampleScenarios) {
         try {
            ExecutionUnitRunner exampleScenarioRunner =
               new RestExecutionUnitRunner(runtime, scenario, jUnitReporter,
                  cucumberFeature);
            runners.add(exampleScenarioRunner);
         } catch (InitializationError initializationError) {
            initializationError.printStackTrace();
         }
      }
      return runners;
   }

   @Override
   protected String getName() {
      return cucumberExamples.getExamples().getKeyword() + ": "
         + cucumberExamples.getExamples().getName();
   }

   @Override
   public Description getDescription() {
      if (description == null) {
         description =
            Description.createSuiteDescription(getName(), cucumberExamples.getExamples());
         for (Runner child : getChildren()) {
            description.addChild(describeChild(child));
         }
      }
      return description;
   }

   @Override
   public void run(final RunNotifier notifier) {
      jUnitReporter.examples(cucumberExamples.getExamples());
      super.run(notifier);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy