Assertions that have been qualitatively designed constitute the most expressive and evocative part of the test.
[highlight dark=”no”]It’s an assertion that verifies that software works in the way that a user and a client expect.[/highlight]
Qualitative assertions should express the test’s task from the first line.
[highlight dark=”no”]Automation tests should never contain cycles that hide assertions inside.[/highlight]
Many of today’s libraries support the assertions based on popular programming languages.
You may think: what is the point of studying numerous libraries if you can use one and prepare automation tests on the basis of one established script?
The answer is simple: assertions that are easily read is the simplest way of creating assertions in a clearer and more accessible way.
There are 2 approaches to writing asserts. First: using the “asserts” keyword, second – using the “should” and “expect” words.
When the first one originates from a classical method of writing unit tests and focuses its attention on testing and verification, the second one (BDD) is completely oriented at such word combinations as “should” and “expect”, that describe the software behavior that is completely expected by a tester.
And now let’s analyze the structure of popular libraries that can be used in the everyday activity of an automated tester.
Hamcrest
It’s probably the most popular library from this field of software automation testing.
The main method used in it is called assertThat().
It’s great that this library can offer various matchers, for example:
You can find more information about this library here: https://code.google.com/p/hamcrest/wiki/Tutorial
FestAsserts
https://joel-costigliola.github.io/assertj/assertj-core-migrating-from-fest.html
It’s a popular Java library that gives personal access to write assertions.
It’s aimed at increasing the readability of a test script and simplifying the process of test execution.
By the way, this library is very similar to the first one since it offers numerous matchers.
For example, to test that the X list contains certain elements.
AssertJ
https://joel-costigliola.github.io/assertj/
It’s a classical branch of the above-mentioned Fest Asserts library that offers numerous assertions, error messages, and this gives the possibility to improve the readability of a test software code.
More details about this library can be found here: http://joel-costigliola.github.io/assertj/
Google Truth
It’s easily read and is clearer than the other three tools.
Conclusion
Therefore, Hamcrest and FestAssert are very important if you use a Java-based BDD approach but Hamcrest is more flexible and scalable; at the same time, Fest Assert has a simple syntax and can be easily used by a common user.
As for AssertJ, this library is a simpler version of FestAssert, that has numerous useful functionalities.
But in general, all the above-mentioned libraries are good for creating simple and working unit tests while performing automated software testing.
0 Comments