Asserting that a particular exception is thrown in Cucumber

前端 未结 4 1746
北海茫月
北海茫月 2021-02-02 13:20

Scenario

I\'m writing a library (no Ruby on Rails) for which I\'d like to have very detailed Cucumber features. This especially includes describing erro

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-02 13:53

    I'm answering from the perspective of someone who uses Cucumber features in a Behavior-Driven Development situation, so take it or leave it...

    Scenarios should be written to test a 'feature' or functionality of the application, as opposed to being used to test the code itself. An example being:

    When the service is invoked
    Then a success code should be returned
    

    It sounds like your test case (i.e. If I do this, then this exception should be thrown) is a candidate for unit or integration testing - in my case, we would use some Mocking or unit testing framework.

    My suggestion would be to re-evaluate your feature scenarios to see if they are really testing what you intend them to test. From personal experience, I've found that if my test classes are becoming abnormally complex, then my features are 'wrong.'

提交回复
热议问题