From the course: Cucumber Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Cucumber hooks: Adding hooks

Cucumber hooks: Adding hooks

From the course: Cucumber Essential Training

Start my 1-month free trial

Cucumber hooks: Adding hooks

- [Instructor] Cucumber Hooks. If you have worked with unit testing tools before, you have probably seen setup and teardown methods. That's exactly what Cucumber Hooks use. Cucumber Hooks are classes that contain methods that have special annotations, namely before and after, and those methods execute before or after each scenario. Let's see Cucumber Hooks in action. I'm going to define my hooks class, but before that, let's define a package called hooks. Within the package, I'm going to define a new class, and I'm going to call it RestaurantSystemHooks. My class is created, so let's go ahead and define two methods here. First one, public void BeforeDisplayMessage. And let's define another method here called AfterDisplayMessage. We're going to apply special annotations to these so this will be @Before and I'm going to import the Before from cucumber.api.java and not from JUnit. Let's annotate the second method. Once again, use cucumber.api.java. Let's show a message here, so I'm just…

Contents