[TIP] Cannot run coverage.exe against the jython
ned at nedbatchelder.com
Mon Aug 4 08:18:33 PDT 2014
On 8/4/14 10:19 AM, Chris Bannan wrote:
> I am a consultant working on some python testing tools for a Java
> I am using Python 2.7, Jython 2.7b2 and Java 7 on Windows 7
> Python is the language of choice for test scripting for my customer.
> Some of the tools require calling java classes. That is easy enough
> using Jython.
> But, I am struggling how to get code coverage data for the
> jython/python code.
> My command line for executing the Unit test is
> java -cp \jython2.7b2\jython.jar org.python.util.jython
> I cannot run coverage.exe against the python/jython below.
> The command line I am using is
> coverage run TestClassForName.py
You show the command you're running, but you haven't shown what
happens. How doesn't it work?
> Coverage does work for other python unittests
> Thanks in advance
> C Bannan
> """Unit test sample for Jython
> import unittest
> from java.lang import Class
> from java.lang import ClassNotFoundException
> class TestClassForName(unittest.TestCase):
> def test_ShouldFailWithInvalidClassName(self):
> return_value = load_class('java.lang.Spring')
> self.assertEquals(return_value, 'failure')
> def test_ShouldPassWithValidClassName(self):
> return_value = load_class('java.lang.String')
> self.assertEquals(return_value, 'success')
> def load_class(class_name):
> # for non Java folks, this causes 'class_name' to be loaded
> jclass = Class.forName(class_name).newInstance()
> return 'success'
> except ClassNotFoundException as cnf_excp:
> return 'failure'
> if __name__ == '__main__':
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python