2

I'm trying to implement a sort of soft assertions in my selenium project with Cucumber.

Basically I'm running the scripts as JUnit tests using the JUnit Eclipse plugin, and I was wondering if there is any way that I can perform multiple assertions on a step, and if any of the assertions fail, I would like to mark the step as failed, but continue with the other steps/assertions in the scenario without interrupting the execution.

By marking failed steps I mean flagging the failure and adding to the FAILED counter in JUnit, for each assertion that fails, regardless of where it happened.

I've noticed that if I catch the assertion error using

try { 
    AssertTrue(someCondition.isTrue()); 
} catch (AssertionError ae) { 
    log.info(some message); 
}

the step will be marked as PASSED in the JUnit plugin, and the failed counter stays 0.

What triggers the counter and how do I manually mark a JUnit failure without throwing an AssertionError?

Alternatively, is there a Cucumber option that I can add to the Runner in order to not stop tests on failures? I'd like to at least have the failures with expected and actual result in the cucumber report.

Sorin D.
  • 91
  • 3
  • 12
  • Possible duplicate of [continue running cucumber steps after a failure](https://stackoverflow.com/questions/15298521/continue-running-cucumber-steps-after-a-failure) – André Barbosa Jan 31 '18 at 14:57

3 Answers3

1

What you are saying is: Can I have multiple assertions that will each execute?

Yes you can, but you will have to write a test for each assertion, for example by using an Example Table or the Background setup offered by Cucumber. In general, you will want to have your scenario only test a single thing.

Koen Prins
  • 71
  • 3
  • I was hoping to avoid writing a test for each assertion, but thanks for the suggestion. What I really want is a way to tell the JUnit plugin to mark a failure so that I can mark multiple failures in the same test. – Sorin D. Feb 01 '18 at 08:19
  • that is the point, JUnit (and other testing frameworks) are build to stop after a failure as it casts uncertainty on all other asserts, considering the application is not behaving as expected. – Koen Prins Feb 01 '18 at 16:34
0

Assertion will definitely stop the test , incase you know that your code is going to faile you can use AsserFailed and try it, else you can if statement and verify the the step without using the JUnit assertion

anir
  • 84
  • 4
0

This may be late, but you can use TestNG or AssertJ library for your assertions The already have soft assert implemented