I want to use assertion in cucumber to verify my test output, can some please write me an example how to do the same in cucumber.

As I googled, I found that people use junit/TestNG assertions like below:

assertTrue(selenium.isTextPresent("Name of the Customer"));

Can I use the same assertions in cucumber test and how?

  • To add in more inputs, I am using cucumber with Junit runner class for my testing framework.
    – Rose
    Jul 4 '17 at 2:31

You need to import Junit.Assert in your Step Definition file and then you can use them as normal assert statements inside the Step Implementation.

For example,

@Then(​"^the total price should be (\\d+)c$"​)
​public​ ​void​ theTotalPriceShouldBeC(​int​ total) ​throws​ ​Throwable​ {
    assertEquals(total, checkout.total());
  • Hi , I am not able to import this class "import org.junit.Assert"
    – Rose
    Jul 4 '17 at 9:49
  • I am getting error as import can not be resolved
    – Rose
    Jul 4 '17 at 9:50
  • Please add the Junit .jar file in your project. Jul 4 '17 at 9:59
  • I have already added junit dependency in pom file as below:
    – Rose
    Jul 4 '17 at 10:04
  • <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency>
    – Rose
    Jul 4 '17 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.