mardi 29 janvier 2019

SonarQube - Is there basic example/explanation of how coverage issues can be resolved?

I'm very new to using SonarQube/Cloud (so please be gentle!) and am trying to work out how to improve the '0% coverage on new code' that my code has.

Here's an example:

I added the code:

    validation_errors = []

    for field in required:
        if field not in request.POST:
            validation_errors.append("field '{0}' missing".format(field))

    if len(validation_errors) > 0:
        return JsonResponse({'errors': validation_errors}, status=400 )

and I have a (Django) test for this:

def test_required_params(self):
        # no username
        response = self.client.post(self.url, { 'password': 'secret', 'media_file': self.video_file })
        self.assertRaises(forms.ValidationError)
        self.assertEqual(response.status_code, 400)

But when I run the sonar-scanner, in the online report, I get the message that these lines are not covered (see: https://sonarcloud.io/component_measures?id=django_oppia&metric=new_coverage&selected=django_oppia%3Aapi%2Fmedia.py)

I'm sure I must have some very basic mis/non-understanding of what the coverage metric actually means.

I'd really appreciate if someone could explain to me what I need to add/update in my code (just the specific example above), so the SonarCloud analysis doesn't continue to flag this as not covered.

Thanks for your help - if you need any extra info on code/platform/versions etc, just let me know.

Aucun commentaire:

Enregistrer un commentaire