F. Lombok and JUnit Testing

Git Link

  1. Git Project
  2. Spring Batch on GIT

1. Lombok

Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and much more.
  • To add lombok on the project, just add the dependency :


After that you can use the lombok's annotations :
  • @Data
  • @Getter
  • @Setter
  • @NoArgsConstructor

2. Test dependency (pom.xml)

  • JUnit 
  • Spring data test
  • Mockito

3. Configuration and execute test

  • Create test package :
com.java.spring.service on src/test/java
  • Create the properties file
/spring-boot-and-liquibase-tutorial/src/test/resources/application-test.properties to active the spring profile test and to override the datasource.
  • Override datasource for unit testing
# Override datasource for test.spring.datasource.jdbcUrl=jdbc:h2:mem:H2DB_UNIT_TESTING;DB_CLOSE_DELAY=-1;MODE=MSSQLServer;DB_CLOSE_ON_EXIT=FALSE

# spring profile for TEST.spring.profiles.active=test

  • Test class
RegionServiceTest.java
  • Testing header


On the GitHub project you can see the class implementation, at this point you can execute the JUnit Test case with Eclipse.
  • Just execute the JUnit Test on maven


Comments