6
donuts
4y

I'm running into an issue with code coverage... I ran the analysis and it's penalizing unused getter, setters, equals, hashcode.

And the thing is I need those getters so GSON will serialize the fields...

How do you make coverage always > 80%?

Based on current analysis, I only get 60.

Comments
  • 7
    Coverage is an adviser. Not a god.
  • 1
    Depending on the coverage tool, you might be able to ignore the g/setters
  • 0
    @iiii well we have a quality gate now where test coverage must be more then 80%...
  • 1
    @donuts every coverage tool should have an option to mark something to be ignored.
  • 0
    @halfflat yes we get melee a hack they I think used reflection too get all the getters and setters and just called them but why?

    I don't even get this rule, unused methods should be removed...

    Who the fuck goes: "so I need to implement this new function, let me check got history to see if someone else implemented something like this before but had to remove it because code quality complained..."
  • 1
    Just put ignores in the test runner definition.
  • 3
    As long as it's @SortOfTested...
  • 0
    @nitwhiz I basically wrote a functional test to get that 60%. There code generates a report from another report a so I just wrote a test that reads in the first report...

    And that should theoretically be near 100% coverage since the program was designed using it...
  • 0
    In this day and age, there's really little reason to not use Lombok to generate all that boilerplate.
  • 0
    @AlmondSauce well what if some fields need custom getters or shouldn't have a getter/setter?
  • 0
    @donuts ...then surely you just annotate the fields where you want standard getters/setters? And if you're using GSON, wouldn't they need to be standard anyway?
  • 1
    @AlmondSauce for lomboq? I don't read much into the docs but just used @Data except that exposes all fields?
  • 0
    The simplest way to get gson to serialize a field is to define a public getter, and vice versa, if not defined, it won't serialize the field.
  • 1
    @donuts Yeah, Lombok. Have a look at the docs. There's heaps of annotations with heaps of options. You can, for instance, just define @Getter and/or @Setter on each field individually.
  • 0
    @donuts 🔔
Add Comment