|
| 1 | +There are two ways to us the PyMock framework. As standalone or as a unittest testcase. If used in standalone mode, we need to create a controller, and when used as a unittest testcase, the controller is created automatically for us. |
| 2 | + |
| 3 | +Stana |
| 4 | + |
| 5 | + |
| 6 | +============================================= |
| 7 | +1. Explain and run write_user_details.py |
| 8 | +2. Explaina and Test the output file with test_write_user_details.py |
| 9 | +3. Explain the drawbacks of the plumbing we have to do with this type of test. Explain why we need to automate the accepting of UserInput |
| 10 | +4. Explain and run test_write_user_details_istub.py and show it's benefits. This is a one step process. However, we are still writing to a file. This too is not good. |
| 11 | +5. Explain and run test_write_user_details_iostub.py |
| 12 | +6. This is good but we cannot wrote stubs for everything in a large project. It will take too long to do it |
| 13 | +7. Here is where mocking comes in. Explain and run test_write_user_details_mock.py |
| 14 | +8. We cannot manually run so many test cases. Here is where test suites come in the picture |
| 15 | +9. unittest also supports test discovery |
| 16 | + python -m unittest discover |
| 17 | + |
| 18 | + |
| 19 | +class MyTestCase(unittest.TestCase): |
| 20 | + |
| 21 | + @unittest.skip("demonstrating skipping") |
| 22 | + def test_nothing(self): |
| 23 | + self.fail("shouldn't happen") |
| 24 | + |
| 25 | + @unittest.skipIf(mylib.__version__ < (1, 3), |
| 26 | + "not supported in this library version") |
| 27 | + def test_format(self): |
| 28 | + # Tests that work for only a certain version of the library. |
| 29 | + pass |
| 30 | + |
| 31 | + @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") |
| 32 | + def test_windows_support(self): |
| 33 | + # windows specific testing code |
| 34 | + pass |
| 35 | + |
| 36 | +@unittest.skip("showing class skipping") |
| 37 | +class MySkippedTestCase(unittest.TestCase): |
| 38 | + def test_not_run(self): |
| 39 | + pass |
| 40 | + |
| 41 | +class ExpectedFailureTestCase(unittest.TestCase): |
| 42 | + @unittest.expectedFailure |
| 43 | + def test_fail(self): |
| 44 | + self.assertEqual(1, 0, "broken") |
| 45 | + |
| 46 | +Resources: |
| 47 | +========== |
| 48 | +Python unittest http://docs.python.org/library/unittest.html |
0 commit comments