Java Unit Tests make easy Random Values with Podam
In this article Java Unit Tests make easy - Random Values with PODAM, we discuss how to generate random values to object, collections we use on Junit test using PODAM library.
Java Unit Tests make easy β Random Values with PODAM
Using PODAM in Spring boot application
We have to add podam dependencies to the spring boot project.
Please use the latest version. When Iβm writing this article, the latest version is 7.2.5.RELEASE
For Maven
<dependency>
<groupId>uk.co.jemos.podam</groupId>
<artifactId>podam</artifactId>
<version>7.2.5.RELEASE</version>
<scope>test</scope>
</dependency>
For Gradle
testCompile group: 'uk.co.jemos.podam', name: 'podam', version: '7.2.5.RELEASE'Pojo using podom
@Test
void testFindAuthorByUserId() {
PodamFactory factory = new PodamFactoryImpl();
AuthorDoc authorDoc = factory.manufacturePojo(AuthorDoc.class);
when(authorRepository.findById(anyLong())).thenReturn(authorDoc);
AuthorDto result = authorService.findAuthorByUserId(Long.valueOf(1));
Assertions.assertEquals(authorDoc.getUserId(), result.getUserId());
Assertions.assertEquals(authorDoc.getFirstName(), result.getFirstName());
Assertions.assertEquals(authorDoc.getBooks().size(), result.getBooks().size());
}===========================================================================
Iβm passionate about continuously learning and exploring new technologies, which will enhance my expertise status. Currently, I'm working as a Technical Lead.
-
π I regularly write articles on https://onloadcode.com/
-
π« How to reach me author@onloadcode.com
