Selenium For Beginners

Assertions

How to write better assertions

Alex Siminiuc's avatar
Alex Siminiuc
Oct 05, 2025
∙ Paid

A good Selenium test should have as few as possible assertions.

These assertions should be

  • clear

  • simple

  • short

  • with error messages

  • with as little duplication as possible

Most of the Selenium Java projects use for assertions either jUnit or TestNG.

Personally, I prefer TestNG as, in the past, it offered lots of advantages over jUnit (things may be different today).

We will go through a few different examples and see different ways of creating assertions for them:

  1. String Assertions

  2. List<String> Assertions

  3. List<Object> Assertions

  4. Filtered List Assertions


Keep reading with a 7-day free trial

Subscribe to Selenium For Beginners to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Alex Siminiuc · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture