views:

13

answers:

2

I have a python script which generates some reports based on a DB. I am testing the script using java Db Units which call the python script. My question is how can I verify the code coverage for the python script while I am running the DB Units?

A: 

I don't know how you can check for inter-language unit test coverage. You will have to tweak the framework yourself to achieve something like this.

That said, IMHO this is a wrong approach to take for various reasons.

  1. Inter-language disqualifies the tests from being described as "unit". These are functional tests. and thereby shouldn't care about code coverage (See @Ned's comment below).
  2. If you must (unit) test the Python code then I suggest that you do it using Python. This will also solve your problem of checking for test coverage.
  3. If you do want to function test then it would be good idea to keep Python code coverage checks away from Java. This would reduce the coupling between the Java and Python code. Tests are code after all and it is usually a good idea to reduce coupling between parts.
Manoj Govindan
"functional tests shouldn't care about code coverage": what an odd statement. Certainly unit tests need coverage measurement, and if you had complete coverage with unit tests you wouldn't need to measure it with functional tests. But there's nothing incompatible between functional tests and coverage measurement. Measure what you have, there's no need to be dogmatic about it.
Ned Batchelder
Fair enough. When I wrote that I was thinking more in terms of black box, API tests. But your point is still valid. I stand corrected.
Manoj Govindan
A: 

Coverage.py has an API that you can use to start and stop coverage measurement as you need.

I'm not sure how you are invoking your Python code from your Java code, but once in the Python, you can use coverage.py to measure Python execution, and then get reports on the results.

Drop me a line if you need help.

Ned Batchelder