AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Dog mocks corgi12/28/2023 ![]() ![]() Let’s add these cases and improve on the existing test name a little bit. What happens if I add a positive and a negative number? Two negative numbers? One positive and one negative?.Are there more test cases I should cover?.We won’t focus on any implementations in this blog post.Īnother way of thinking about Arrange, Act, Assert is Given, When, Then.Īfter we write our sum implementation, we can ask ourselves some questions: If it is, the test will pass and fail otherwise. In our case, that object is AbstractIntegerAssert with methods for testing Integers. The returned object has methods that make sense for the object we passed to the assertThat method. assertThat(result) method is part of the AssertJ library and has multiple overloads.Įach overload returns a specialized Assert object. This is the assert phase in which we inspect what happened and if everything resolved as expected. ![]() This is the act phase where we trigger the behaviour we want to test.All we need for this test is to have a Calculator instance. This is the arrange phase of our test, where we prepare the testing environment.It is perfectly normal to have private methods in the test class which are not tests. annotation lets JUnit framework know which methods are meant to be run as tests.I prefer using the ClassShould naming convention when writing tests to avoid repeating should or test in every method name. class CalculatorShould // 1Ĭalculator calculator = new Calculator() // 2 The first example of a test we will look at is a simple calculator for adding 2 numbers. AssertJ is a Java library that helps developers write more expressive tests. JUnit is the most popular testing framework for Java. While the examples in this post are written using JUnit 5 and AssertJ, the lessons are applicable to any other unit testing framework. In this blog, we’re focusing on real examples. We’re continuing with our series of blogs about everything related to testing.
0 Comments
Read More
Leave a Reply. |