Skip to content

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