0

I have Web Application where the source code is in Python. All the regression tests are in Java. I wish to perform Code Coverage for the application. Please suggest a code coverage tool to instrument the python application .I should then be able to execute Java selenium tests over it and fetch coverage report

asked Jul 30, 2020 at 6:54
2
  • What type of coverage are you interested in? E.g., if you want to investigate the endpoints you are hitting and the request trace, something like OpenTracing or OpenCensus may help, For other types of coverage (see here sqa.stackexchange.com/a/44995/12740), other tools may be more appropriated. Commented Jul 30, 2020 at 14:24
  • Basically, I wanted to get the code coverage% of the application's source code against the selenium automation tests . For example - X% of code is covered by "Y" number of tests. This is to ensure how much % of code is hit by automation tests Commented Jul 30, 2020 at 21:05

1 Answer 1

1

You should install coverage package. I have both python2 and python3 on my computer so I'll show you how to deal with my case and python 3.

So say you have the following program:

g = input("Enter your age: ") 
if int(g) < 15:
 print("You are a child")
else:
 print("You are not a child")
  1. Install coverage tool: pip3 install coverage
  2. Use coverage tool to run your application under test: coverage3 run undertest.py
  3. Perform your tests (e.g. input 5 when prompted - in your case you would run your Selenium test suite)
  4. Where you have run your app under test you should now see .coverage file.
  5. Run coverage3 html. You should now have html report generated at the same folder.

Result:

enter image description here

Disclaimer: Since I have both 2 and 3 versions of python at the same time I need to use commands which explicitly use version 3. I am not sure what would be the behavior if you have only version 3. So if those commands won't work for you, try to omit 3 (e.g. pip install coverage or coverage run blah-blah-blah)

answered Jul 31, 2020 at 14:48
3
  • Thanks for the explanation , Alexey. So, once my web application is run using coverage command, as mentioned in 3rd step, java-selenium tests can be executed against the application. Is my understanding right ? Also , when would ".coverage" file get generated? Do we have ways to manually stop the coverage ? Please clarify. Commented Aug 2, 2020 at 19:57
  • Yes. You can run your selenium tests or even manual tests. coverage file is being altered all the way your tests are running. Basically it is a SQLite database. You can stop your application and your coverage will be stopped. Commented Aug 2, 2020 at 20:13
  • This helps ! Thanks Alexey. Will implement using coverage.py Commented Aug 3, 2020 at 10:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.