#language: ja フィーチャ: 受注業務 シナリオテンプレート: 受注 前提 在庫数が <処理前在庫> である もし <注文> 個注文する ならば 受注が<注文結果>する ならば 在庫数が <処理後在庫> になる 例: |処理前在庫|注文|注文結果|処理後在庫| |20|10|成立|10| |10|20|失敗|10|
#language: ja フィーチャ: 受注業務 シナリオテンプレート: 受注 前提 在庫数が <処理前在庫> である もし <注文> 個注文する ならば 受注が<注文結果>する ならば 在庫数が <処理後在庫> になる 例: @Excel(@Excel(src/test/resources/features/xxx.xlsx,sheet1)
package com.mycompany.cucumberexam; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions( features = {"src/test/resources/features/example1.feature"}, format = {"pretty"}, monochrome = true ) public class Example1Test { }
package cucumber.runtime.io; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class FileResource implements Resource { private final File root; private final File file; public FileResource(File root, File file) { this.root = root; this.file = file; if (!file.getAbsolutePath().startsWith(root.getAbsolutePath())) { throw new IllegalArgumentException(file.getAbsolutePath() + " is not a parent of " + root.getAbsolutePath()); } } @Override public String getPath() { if (file.equals(root)) { return file.getPath(); } else { return file.getAbsolutePath().substring(root.getAbsolutePath().length() + 1); } } @Override public InputStream getInputStream() throws IOException { return new FileInputStream(file); } @Override public String getClassName() { String path = getPath(); return path.substring(0, path.length() - 6).replace(File.separatorChar, '.'); } }
import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @Aspect public class FeatureReadAddon { @Around("call(public java.io.InputStream cucumber.runtime.io.Resource.getInputStream())") public InputStream afterExecute(ProceedingJoinPoint thisJoinPoint){ try { InputStream in = (InputStream) thisJoinPoint.proceed(thisJoinPoint.getArgs()); // TODO : この in で feature ファイルの中身を返すので、 // FilterInputStream で、 // 例: // @Excel(src/test/resources/xxx.xlsx,sheet1) // を // 例: // |No|Name|Sex|Age| // |1|Sachi|Female|26| // |2|Miwa |Female|32| // に置き換えてやればいい return in; } catch (Throwable ex) { Logger.getLogger(FeatureReadAddon.class.getName()).log(Level.SEVERE, null, ex); throw new RuntimeException(ex); } } }
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>info.cukes</groupId> <artifactId>cucumber-core</artifactId> <version>1.1.6-Ext</version> <packaging>jar</packaging> <name>Cucumber Core Ext</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.6.11</version> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-core</artifactId> <version>1.1.7</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.4</version> <configuration> <complianceLevel>1.6</complianceLevel> <source>1.6</source> <target>1.6</target> <weaveDependencies> <weaveDependency> <groupId>info.cukes</groupId> <artifactId>cucumber-core</artifactId> </weaveDependency> </weaveDependencies> </configuration> <executions> <execution> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>