Created
September 25, 2017 12:04
-
-
Save sriv/8f7b12d5e06cf38a140b32e88c4d5d72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'java' | |
apply plugin: 'gauge' | |
apply plugin: 'application' | |
description = "Foo" | |
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'com.thoughtworks.gauge.gradle:gauge-gradle-plugin:+' | |
} | |
} | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
compile 'com.thoughtworks.gauge:gauge-java:+' | |
} | |
// configure gauge task here (optional) | |
gauge { | |
specsDir = 'specs' | |
tags = 'V1' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>gradle gauge --rerun-tasks | |
:compileJava NO-SOURCE | |
:processResources NO-SOURCE | |
:classes UP-TO-DATE | |
:compileTestJava | |
:processTestResources NO-SOURCE | |
:testClasses | |
:gauge | |
[DEPRECATED] This usage will be removed soon. Run `gauge help --legacy` for more info. | |
Unable to start plugin html-report. Plugin html-report is not installed. To install, run `gauge install html-report`. | |
# Specification Heading | |
Tags in scenario [V1] | |
## Vowel counts in single word P P | |
## Vowel counts in multiple word P P | |
Specifications: 1 executed 1 passed 0 failed 0 skipped | |
Scenarios: 2 executed 2 passed 0 failed 0 skipped | |
Total time taken: 28ms | |
BUILD SUCCESSFUL | |
Total time: 2.019 secs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Specification Heading | |
===================== | |
This is an executable specification file. This file follows markdown syntax. | |
Every heading in this file denotes a scenario. Every bulleted point denotes a step. | |
To execute this specification, run | |
gauge specs | |
tags: V1 | |
* Vowels in English language are "aeiou". | |
Vowel counts in single word | |
--------------------------- | |
tags: single word | |
* The word "gauge" has "3" vowels. | |
Vowel counts in multiple word | |
----------------------------- | |
This is the second scenario in this specification | |
Here's a step that takes a table | |
* Almost all words have vowels | |
|Word |Vowel Count| | |
|------|-----------| | |
|Gauge |3 | | |
|Mingle|2 | | |
|Snap |1 | | |
|GoCD |1 | | |
|Rhythm|0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.thoughtworks.gauge.Step; | |
import com.thoughtworks.gauge.Table; | |
import com.thoughtworks.gauge.TableRow; | |
import com.thoughtworks.gauge.ExecutionContext; | |
import com.thoughtworks.gauge.BeforeSpec; | |
import java.util.HashSet; | |
import static org.junit.Assert.assertEquals; | |
public class StepImplementation { | |
private HashSet<Character> vowels; | |
@BeforeSpec(tags = "V1") | |
public void beforeSpec(ExecutionContext context) | |
{ | |
System.out.println("Tags in scenario "+context.getAllTags()); | |
} | |
@Step("Vowels in English language are <vowelString>.") | |
public void setLanguageVowels(String vowelString) { | |
vowels = new HashSet<>(); | |
for (char ch : vowelString.toCharArray()) { | |
vowels.add(ch); | |
} | |
} | |
@Step("The word <word> has <expectedCount> vowels.") | |
public void verifyVowelsCountInWord(String word, int expectedCount) { | |
int actualCount = countVowels(word); | |
assertEquals(expectedCount, actualCount); | |
} | |
@Step("Almost all words have vowels <wordsTable>") | |
public void verifyVowelsCountInMultipleWords(Table wordsTable) { | |
for (TableRow row : wordsTable.getTableRows()) { | |
String word = row.getCell("Word"); | |
int expectedCount = Integer.parseInt(row.getCell("Vowel Count")); | |
int actualCount = countVowels(word); | |
assertEquals(expectedCount, actualCount); | |
} | |
} | |
private int countVowels(String word) { | |
int count = 0; | |
for (char ch : word.toCharArray()) { | |
if (vowels.contains(ch)) { | |
count++; | |
} | |
} | |
return count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment