
Petri Kainulainen Blog
1,000 FOLLOWERS
Petri Kainulainen is passionate about software development and continuous improvement. He is specialized in software development with the Spring Framework and is the author of Spring Data book.
Petri Kainulainen Blog
1M ago
When we are writing automated tests for our code, often we notice that it's not possible to invoke the real dependencies of the system under test. The problem might be that:
The problematic dependency invokes an external API which cannot be accessed from our test environment.
We cannot invoke the real dependency because invoking it would cause unwanted side effects.
The real dependency is too slow and invoking it would slow down our test suite.
If we cannot use the real dependency, we have to replace it with a test double that must provide the same API as the replaced dependency. This ensure ..read more
Petri Kainulainen Blog
3M ago
When we are writing automated tests for our code, often we notice that it's not possible to invoke the real dependencies of the system under test. The problem might be that:
The problematic dependency invokes an external API which cannot be accessed from our test environment.
We cannot invoke the real dependency because invoking it would cause unwanted side effects.
The real dependency is too slow and invoking it would slow down our test suite.
If we cannot use the real dependency, we have to replace it with a test double that must provide the same API as the replaced dependency. This ensure ..read more
Petri Kainulainen Blog
4M ago
When we are writing automated tests for our code, often we notice that it's not possible to invoke the real dependencies of the system under test. The problem might be that:
The problematic dependency invokes an external API which cannot be accessed from our test environment.
We cannot invoke the real dependency because invoking it would cause unwanted side effects.
The real dependency is too slow and invoking it would slow down our test suite.
If we cannot use the real dependency, we have to replace it with a test double that must provide the same API as the replaced dependency. This ensure ..read more
Petri Kainulainen Blog
6M ago
When we are writing automated tests for our code, often we notice that it's not possible to invoke the real dependencies of the system under test. The problem might be that:
The problematic dependency invokes an external API which cannot be accessed from our test environment.
We cannot invoke the real dependency because invoking it would cause unwanted side effects.
The real dependency is too slow and invoking it would slow down our test suite.
If we cannot use the real dependency, we have to replace it with a test double that must provide the same API as the replaced dependency. This ensure ..read more
Petri Kainulainen Blog
8M ago
When we are writing automated tests for our code, often we notice that it's not possible to invoke the real dependencies of the system under test. The problem might be that:
The problematic dependency invokes an external API which cannot be accessed from our test environment.
We cannot invoke the real dependency because invoking it would cause unwanted side effects.
The real dependency is too slow and invoking it would slow down our test suite.
If we cannot use the real dependency, we have to replace it with a test double that must provide the same API as the replaced dependency. This ensure ..read more
Petri Kainulainen Blog
9M ago
The previous parts of my Spring MVC Test tutorial described how you we can write unit tests for a Spring MVC REST API when the system under test returns the information of a single item or returns a list. In other words, now we know how we can write unit tests for Spring MVC controllers which return data as JSON.
It's time to take the next step. This blog post describes how we can write unit tests for a Spring MVC REST API endpoint which reads data from the request body, inserts valid data into a database, and returns data as JSON.
After we have finished this blog post, we:
Know how we can se ..read more
Petri Kainulainen Blog
11M ago
The previous part of my Spring MVC Test tutorial described how we can write unit tests for Spring MVC controllers which return the information of a single item as JSON. This blog post provides more information about writing unit tests for a Spring MVC REST API. To be more specific, this blog post describes how we can write unit tests for a Spring MVC controller that returns a list as JSON.
After we have finished this blog post, we:
Know how we can ensure that the system under test returns the correct HTTP status code.
Can verify that the system under test returns the correct information.
Let ..read more
Petri Kainulainen Blog
11M ago
The previous part of my Spring MVC Test tutorial described how we can send HTTP requests to the system under test and write assertions for the response returned by the tested controller method. This blog post describes how we can use the information provided by the previous part of this tutorial when we are writing unit tests for a controller method which returns the information of a single item as JSON.
After we have finished this blog post, we:
Know how we can ensure that the system under test returns the correct HTTP status code.
Can verify that the system under test returns the correct in ..read more
Petri Kainulainen Blog
11M ago
Earlier we learned that we should configure the system under test by using the standalone configuration when we are writing unit tests for Spring MVC controllers.
In this blog post, we will put theory into practice. This blog post describes how we can use the standalone configuration when we are writing unit tests for Spring MVC controllers which implement a REST API.
After we have finished this blog post, we:
Understand how we can create and configure the required components without adding duplicate code to our test suite.
Know how we can send HTTP requests to the system under test without a ..read more
Petri Kainulainen Blog
1y ago
The previous part of my Spring MVC Test tutorial described how we can write unit tests for a Spring MVC controller that renders a list. This blog post provides more information about writing unit tests for Spring MVC controllers which insert data into the used database. To be more specific, this blog post describes how we can write unit tests for a Spring MVC controller that submits a form.
After we have finished this blog post, we:
Know how we can submit a form by using the Spring MVC Test framework.
Understand how we can ensure that the system under test displays the correct validation erro ..read more