Swapnil Waghmare asks…
Are BDD frameworks like Specflow, Cucumber better for E2E tests?
There’s two ways I can interpret this question (my additions are in bold).
Are BDD frameworks that use ‘Given/When/Then’ feature files like Specflow, Cucumber better than frameworks that use ‘describe/it’ blocks like RSpec and Mocha for e2e tests?
As I previously explained, Automattic’s unit tests are written in Mocha, so that was a logical choice for writing e2e tests as there is a lot of familiarity of it within Automattic, which will hopefully mean more developers are interested in the e2e tests we are writing using Mocha/WebDriverJs.
There are some challenges with writing end-to-end tests with Mocha (mainly that Mocha tests are all independent so will continue to run if a previous step in the scenarios fails) so I haven’t completely ruled out investigating a move to Cucumber at some point for the e2e tests.
Are BDD frameworks like Specflow, Cucumber better for E2E tests than using them for automated integration, component or unit tests?
I think you could write integration tests or even unit tests in Given/When/Then format as most unit tests follow the same arrange/act/assert pattern anyhow which is exactly what Given/When/Then is.
Keep in mind there is overhead in maintaining all the step definitions and feature files for Cucumber/Specflow that give you non technical readability so if you don’t require that readability it is probably overkill. But a personal preference nonetheless.
Swapnil Waghmare also asks…
Which tools have you used for API testing, which ones would you recommend?
I try to keep things simple, so in the past when I’ve written REST integration tests I’ve just called them using in built libraries, and have used Postman quite a lot for manual testing and debugging.
Swapnil Waghmare finally asks…
As for whether QA’s should write unit tests? No, I don’t think so, as I believe unit tests should drive software development, and writing code by writing unit tests is much easier than trying to add unit tests after by someone else, as the original code will not likely be very testable as it wasn’t written with testability in mind. One benefit of code written with unit tests at the time is that it will mostly be better code as the tests are consuming your API that you are developing.