I have a BookManagementService that uses the @Autowired implementation of three other services, like so So how do I mock the aforementioned services and their repo in the BookManagementServiceTest? When the test start running and it gets to the yearService layer, it throws a NullPointerEXception cause the year it receives is null The BookManagementServiceTest Answer You just have to mock
I want to use Testcontainers with @DataJpaTest (and @SpringBootTest) using JUnit 5. I have the basic setup working using the @Testcontainers and @Container annotation like this: See https://github.com/wimdeblauwe/blog-example-code/tree/feature/testcontainers-datajpatest/testcontainers-datajpatest for the full example code (AtleteRepositoryTest, TeamRepositoryTest and TestcontainersDatajpatestApplicationTests). To avoid the repetition of declaring the PostgreSQL container and the dynamic properties, I tried the following: JUnit 5 extension Baeldung has a
I’m testing a Dao with an In-Memory DB with H2. I’m passing an int to the query with a map to execute it. This query is working OK on Oracle SQL, but is not succeding in H2. DAO @Override public …
I am using Spring for MVC tests Here is my test class Here is the MVC config Here is the security config When I run my test it fails with the message: I understand that it fails due to the fact that the url is protected with spring security, but when I run my application I can access that url
For my Spring-Boot app I provide a RestTemplate though a @Configuration file so I can add sensible defaults(ex Timeouts). For my integration tests I would like to mock the RestTemplate as I dont want to connect to external services – I know what responses to expect. I tried providing a different implementation in the integration-test package in the hope that
My Spring-Boot-Mvc-Web application has the following database configuration in application.properties file: spring.datasource.url=jdbc:h2:tcp://localhost/~/pdk spring.datasource.username=sa spring….
In most projects that use Spring extensively there are a few tests that use @IfProfileValue to mark it as integration test, performance test or similar. When you run these with maven you do something …