JUnit tests for POJOs

后端 未结 17 1701
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:27

    My answer is that trivial getters and setters do not merit their own tests. If I add any code other than simple reads or writes, then I add tests.

    Of course, this is all boilerplate, so you could easily write a script that generates unit tests for your getters and setters, if you think there's any value there. Certain IDEs may allow you to define a template that creates test cases with test methods filled in for this boilerplate code (I'm thinking of IntelliJ here, but Eclipse can probably handle it too, although I haven't done anything like this in either IDE).

提交回复
热议问题