From the course: Cucumber Essential Training
Step definitions: Generate code - Cucumber Tutorial
From the course: Cucumber Essential Training
Step definitions: Generate code
- [Presenter] So the next step is to create step definitions. Let's go ahead and implement the step definition. I'll create a new file and call it "menu management steps." From our previous step, I already have implementations of the three steps, so I'll just go ahead and copy the three methods and paste those here. Let's examine the generated methods in our step definitions class. First of all, the name of the method does not matter. You could name it any Java method that is valid. The second thing to note here is that each method has an annotation that contains text that matches the text specified in our feature file scenario step. Also, because we had specified some of the values, for example, cucumber sandwich and $20, those items are now extracted as method parameters. These values, "string and int," are basically cucumber expressions. So now these parameters or their values are available as parameters in our method. Let's go ahead and implement our first method. As you can see, it's throwing a pending exception. It says the feature menu management runs, but it found a pending exception. Let me go ahead and run this code. As you can see in the output, we got an error, and there is a bill failure. You can see in the output that we got a pending exception, which means even though the method is implemented, it's throwing an exception. You can see in the output that there were a total of two tests that were run with one editing out. Let me show you why you are seeing two tests. This is because we already have an example feature implemented. This comes from the standard template with Maven project creation based on cucumber's official website, and it already has its step definitions implemented, but our new menu management steps test did not succeed because it has a pending exception being thrown from the method. So we need to implement this code.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
User story session: The problem domain1m 39s
-
(Locked)
User story session: Concrete examples1m 53s
-
Feature file5m 4s
-
Step definitions: Generate code3m 1s
-
(Locked)
Step definitions: First domain object2m 29s
-
(Locked)
Step definitions: Next scenario step2m 26s
-
(Locked)
Step definitions: Test scenario6m 2s
-
(Locked)
-
-
-
-
-
-