How do I write JUnit test cases for lombak java files?

2,318 views
Skip to first unread message

Venkatesan Mahendran

unread,
Jul 2, 2019, 12:18:45 PM7/2/19
to Project Lombok

I am using Lombak in my spring boot project. As we know, the POJOs which have annotation @Data will not have any getters and setters. How do I write test cases for these POJOs? This affects my code coverage and doesn't allow me to pass through SonarQube pipeline. Appreciate your help on this. 

Thanks,
Venkat 

Joseph Ottinger

unread,
Jul 2, 2019, 12:31:42 PM7/2/19
to project...@googlegroups.com
But they WILL have accessors and mutators. You can even compile and test them. That's what Lombok is *for*, to generate those things... so you could easily write tests to validate mutators, accessors, equals(), hashcodes, etc., although the wisdom of doing so is questionable.

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/project-lombok/52e3c4f5-2651-4c26-9f08-9f528934adf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Joseph B. Ottinger
http://www.enigmastation.com
Memento mori.

Mat Jaggard

unread,
Jul 2, 2019, 12:36:09 PM7/2/19
to project-lombok
We have a test helper class for testing our standard methods (using Force66 bean tester, another bean tester and an equals and hashcode tester).

However we've done this for one reason only - our company requires a level of test coverage, however pointless and we cannot use the latest version of Sonarqube which automatically ignores code that's generated by Lombok.

Many thanks,
Mat.

Venkatesan Mahendran

unread,
Jul 2, 2019, 12:55:36 PM7/2/19
to Project Lombok
yes, you all are right. Writing test cases for Lombok is pointless but the infra team has created the pipeline and I have no control on it. So, I need to write test cases to cover Lombok objects. I will give a try using "Force66/BeanTester".

Thanks,
Venkat


On Tuesday, July 2, 2019 at 5:31:42 PM UTC+1, Joseph Ottinger wrote:
But they WILL have accessors and mutators. You can even compile and test them. That's what Lombok is *for*, to generate those things... so you could easily write tests to validate mutators, accessors, equals(), hashcodes, etc., although the wisdom of doing so is questionable.

On Tue, Jul 2, 2019 at 12:18 PM Venkatesan Mahendran <venm...@publicisgroupe.net> wrote:

I am using Lombak in my spring boot project. As we know, the POJOs which have annotation @Data will not have any getters and setters. How do I write test cases for these POJOs? This affects my code coverage and doesn't allow me to pass through SonarQube pipeline. Appreciate your help on this. 

Thanks,
Venkat 

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project...@googlegroups.com.

perogi

unread,
Jul 2, 2019, 1:08:14 PM7/2/19
to Project Lombok
What IDE are you using Venkat?  For IntelliJ, it will automatically process annotations so you have those objects available.  Using Gradle/Maven/etc in the pipeline should accomplish the same thing, allowing any tests 

Another idea is if you are using Gradle (and probably other build tools), you can set sonarqube properties in your build.gradle file and exclude your pojo directory.

sonarqube {
  properties {
    property "sonar.exclusions", "**/path/to/your/model/directory/**"
    ...
Reply all
Reply to author
Forward
0 new messages