Skip to content
Advertisement

Tag: junit5

How to combine Testcontainers with @DataJpaTest avoiding code duplication?

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

java.lang.NullPointerException at io.dropwizard.testing.junit5.DropwizardExtensionsSupport.beforeEach

I am trying to test a Dropwizard resource. My test looks like this: However, this gives the error message: which is frankly uninformative. Can someone point out what is wrong here? P/S Here is the CommonObjects constructor: which also explains why I am creating the resource extension before each test case. Answer In the end, instead of using mocks, I

Could not find @BeforeEach setup() method on @Nested test class in @QuarkusTest

summary On Junit Jupiter the Quarkus test extension seems to not find @BeforeEach setup methods for nested test classes and produces an error: java.lang.RuntimeException: Could not find method void com.stackoverflow.examples.nestedtestwithquarkus.NestedTestWithQuarkus.setup() on test class Is that a bug, a feature or am I missing something important? edit 1: It seems like there’s an issue with nested tests in general. Some tests

Eclipse: Gradle source folder migration breaks JUnit test resources

I refactored an Eclipse project with using Java 11.0.10 to match Gradle’s default source and resource folders instead of eclipse’s source and resource folders, like this: I moved the sources and resources to the folders accordingly. When I access a test resource within a JUnit test, like TestClass.class.getResource(“/my/package/mytestresource.xml”) it returns [ProjectFolder]/src/main/resources/my/package/mytestresource.xml and not [ProjectFolder]/src/test/resources/my/package/mytestresource.xml. The test runs over Eclipse’s JUnit

How to mock MapStruct nested mapper in JUnit5

I have been searching a solution for about a day now. I still cannot produce a working example. My problem is simple. I have a mapper uses another mapper: My test class which tests mapper works as it should: However, NullPointerException is thrown on the line where roleMapper is called in automatically generated impl class UserMapperImpl: it comes to my

mocking the response for the method called inside the same class

Iam trying to write JUnit test case for the below class scenario. JUnit for the above class. When the above JUnit test case is executed, it is throwing NullPointerException as the details value returned is null. What is the better approach to solve the above error.TIA. –EDIT– In the above code sample, added the class3 dependency logic for better clarity.

Advertisement