You can control the language of the Gherkin keyword by adding # language: xx
as first line.
For Portuguese it would be
# language: pt
Funcionalidade: um exemplo
A list of all supported spoken languages can be found at https://docs.cucumber.io/gherkin/reference/#spoken-languages. The localized keywords you might lookup for example in gherkin-languages.json
A simple Maven project.
structure
pom.xml
src/test/java/features/example.feature
src/test/java/runner/TestRunner.java
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>com.suboptimal</groupId>
<artifactId>cuke-test-13.so</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.cucumber>3.0.2</version.cucumber>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
src/test/java/features/example.feature
# language: pt
Funcionalidade: um exemplo
Cenario: foo
Dado something given
src/test/java/runner/TestRunner.java
package runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/java/features/example.feature"
)
public class TestRunner {
}
running the test with mvn compile test
will produce the following error.
Undefined scenarios:
src/test/java/features/example.feature:4 # foo
1 Scenarios (1 undefined)
1 Steps (1 undefined)
0m0.036s
You can implement missing steps with the snippets below:
@Dado("something given")
public void something_given() {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
edit When the feature file is saved on Windows with Notepad
as UTF-8
the BOM characters (EF BB BD) are inserted at the beginning.
$ hexdump -C example.feature
00000000 ef bb bf 23 20 6c 61 6e 67 75 61 67 65 3a 20 70 |...# >language: p|
If running mvn test
the execution fails with exception.
cucumber.runtime.CucumberException: gherkin.ParserException$CompositeParserException: Parser errors:
(1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '# language: pt'
(2:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Funcionalidade: um exemplo'
(4:3): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Cenario: foo'
(5:3): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Dado something given'