Choosing a test framework and assertion lib βοΈ
Type | JVM (Java/Kotlin) | Python |
---|---|---|
xUnit style | JUnit, TestNG | pytest, unittest |
BDD | Cucumber | Behave, pytest-bdd |
Think ! π€οΈ Who would be the primary author of these tests?
- Developers, Automation engineers (Choose xUnit)?
- Product managers (PM), Manual testers (BDD can be an option)?
xUnit style π€
Benefits β
- Fast and flexible
- Setup/tear downs at different levels (Suite, Class, Test)
- Easy to data drive/parallelize tests
Tradeoffs β
- Can be less readable (if not well designed)
Tip: π‘ Write tests using arrange-act-assert pattern.
BDD π€
If you think Cucumber is a testing tool, please read on, because you are wrong. - Aslak HellesΓΈy Reference: The worlds most misunderstood collaboration tool
Benefits β
- Readable (Gherkin syntax with
Given/When/Then/And
) - Provides a layer to allow non-coders (PM/Manual test engineers) to also contribute
- More readable test results report
Tradeoffs β
- Maintaining a BDD layer (feature files, step definitions) can be an overhead
- Less flexible
- (Trap πΊ) Feature files can be imperative instead of declarative
Imperative
Given I open a browser
And I navigate to http://example.com/login
When I type in the username field bob97
And I type in the password field F1d0
And I click on Submit button
Then I should see the message Welcome Back Bob
Declarative
Given I am on the Login Page
When I sign in with correct credentials
Then I should see a welcome message
Source: Sauce labs best practices for running tests
Choosing an fluent assertion library π΅π»ββοΈ
Let's not reinvent the wheel βΈοΈ shall we? π
Java/Kotlin | Python |
---|---|
Google Truth βοΈ | assertpy π |
Other choices: Hamcrest, Native JUnit or TestNG