JUnit tests for POJOs

后端 未结 17 1881
Happy的楠姐
Happy的楠姐 2021-02-02 07:56

I work on a project where we have to create unit tests for all of our simple beans (POJOs). Is there any point to creating a unit test for POJOs if all they consist of is gette

17条回答
  •  野性不改
    2021-02-02 08:21

    IMHO POJOs are automatically tested when logic for any functionality is tested, e.g. For testing any functions, we may need to inject/mock certain values, POJOs, and getter/setter for POJOs are indirectly tested.

    However for the specific use-case to eliminate POJOs for unit-testing, it can be achieved following 2 ways:

    1. USE LIBRARY: use existing libraries that help test POJOs. One such library I came across is meanbean.

      Ref: http://meanbean.sourceforge.net/

      Maven: http://mvnrepository.com/artifact/org.meanbean/meanbean (current version: 2.0.3)

    2. IGNORE POJOs: Sonar can be configured to exclude POJOs or specific packages to be excluded from unit-test coverage reports. Few examples below:

      
          
              **/domain/**/*,
              **/pojos/*
          
      
      

提交回复
热议问题