Hope this helps. If you are a full step of worming it looks like this ...
When I see the following cooked I should say: | food | say | | Bacon | Yum! | | Peas | Really? |
You want it in Java. (Note that cucumber.api.DataTable went through the setup with your expected values ββbefore the test).
@When("^I see the following cooked I should say:$") public void theFoodResponse(DataTable expectedCucumberTable) { // Normally you'd put this in a database or JSON List<Cuke> actualCukes = new ArrayList(); actualCukes.add(new Cuke("Bacon", "Yum!")); actualCukes.add(new Cuke("Peas", "Really?")); Another link to a Full Example.diff(actualCukes) }
I will say that in the examples of Aslak Hellesoy he actually does not use DataTable.
He would make your example something like this:
@When("^I see the following cooked I should say:$") public void theFoodResponse(List<Entry> entries) { for (Entry entry : entries) { // Test actual app you've written hungryHuman.setInputValue(entry.food); hungryHuman.setOutputValue(entry.say); } } public class Entry { String food; String say; }
For a complete example for additional validation:
- Millstone calculator: link
- Java Calculator Step Definition: Link
EDIT:
Sorry for the overkill @Christian, you may not need the whole context of how to use it in the application, just a clean way to use DataTable.create, and most of what I wrote is another way to infect this cat with Entry class (which may be useful for those reading this later.)
So you did it in your comment just around the corner. I am not a pro in collections, so I cannot give you any advice on creating your 2D list of strings, but I can clarify the last two parameters (if you use all 4).
- If your columns use the Date or Calendar fields, you can specify Format in the parameter from the second to the last .
- If you do not use the latter for column names, then it will automatically read your top row for column names.
- You can also remove Locale.getDefault () and it will do it for you; so you look at:
.
List<List<String>> infoInTheRaw = Arrays.asList( Arrays.asList("h1", "h2"), Arrays.asList("v1", "v2") ); DataTable dataTable = DataTable.create(infoInTheRaw);
You can also use a constructor that would be just as dirty. :)
Eric D. Johnson
source share