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

ousell.cucumber2junit-maven-plugin.1.5.2.source-code.junitTestClass.vm Maven / Gradle / Ivy

Go to download

Generates plain JUnit tests from Gherkin feature files. This is useful when you want to execute Cucumber tests in an environment which does not allow custom JUnit runners, e.g. the AWS Device Farm.

The newest version!
package $packageName;

import static org.junit.Assert.fail;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/** Generated by cucumber2junit-maven-plugin. */

public class $className {
  
  /**
   * Copy the feature files to the temp folder.
   *
   * @throws IOException {@link IOException}
   */
  @BeforeClass
  public static void init() throws IOException {
    Paths.get("$featuresOutputDirectory").toFile().getParentFile().mkdirs();
    Files.copy(
      ${className}.class.getClassLoader().getResourceAsStream("$featuresClasspath/$feature.getFileName()"),
      Paths.get("$featuresOutputDirectory/$feature.getFileName()"),
      StandardCopyOption.REPLACE_EXISTING);
  }
  
  #foreach($scenario in $scenarios)@Test
  public void $scenario.getCamelCaseName()() throws Throwable {
    if (CucumberMain.runFeatures(
            new String[] {
              "--glue", "$stepsPackage", 
              "$featuresOutputDirectory/$feature.getFileName():$scenario.lineNumber"})
        != 0) {
      fail();
    }
  }
  
  #end
  
  /** Remove the feature files from the temp folder. */
  @AfterClass
  public static void clean() {
    Paths.get("$featuresOutputDirectory/$feature.getFileName()").toFile().delete();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy