Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Test not running

I'm getting stuck with some unittests.

Here's the simplest example I could come up with:

#testito.py import unittest  class Prueba(unittest.TestCase):      def setUp(self):         pass     def printsTrue(self):         self.assertTrue(True)  if __name__=="__main__":     unittest.main() 

Problem is, running this has no effect:

$ python testito.py   ---------------------------------------------------------------------- Ran 0 tests in 0.000s  OK 

I'm scratching my head as I don't see any problem with the code above. It happened with a couple of tests now and I don't really know what to do next. Any idea?

like image 836
tutuca Avatar asked Nov 29 '12 13:11

tutuca


People also ask

What happens if unit testing is not done?

If any of the unit tests have failed then the QA team should not accept that build for verification. If we set this as a standard process, many defects would be caught in the early development cycle, thereby saving much testing time. I know many developers hate to write unit tests.

How do I enable unit testing?

Turn live unit testing from the Test menu by choosing Test > Live Unit Testing > Start.

How do I stop a test case from running in Visual Studio?

You need to close the Test Explorer Window to prevent automatic running.


1 Answers

By default, only functions whose name that start with test are run:

class Prueba(unittest.TestCase):      def setUp(self):         pass     def testPrintsTrue(self):         self.assertTrue(True) 

From the unittest basic example:

A testcase is created by subclassing unittest.TestCase. The three individual tests are defined with methods whose names start with the letters test. This naming convention informs the test runner about which methods represent tests.

like image 129
Martijn Pieters Avatar answered Sep 20 '22 04:09

Martijn Pieters