示例#1
0
    def run(self):
        if not self.module:
            return 'No module found.'

        suite = TestSuite(self.module, self.class_name, self.method_name)
        result = TestResult()
        suite.run(result)
        return result.summary()
示例#2
0
class TestCaseTest(TestCase):
    def setup(self):
        self.result = TestResult()

    def test_template_method(self):
        test = WasRun('test_method')
        test.run(self.result)
        assert test.log[0] == 'setup'
        assert test.log[1] == 'running'
        assert test.log[2] == 'teardown'

    def test_result(self):
        test = WasRun('test_method')
        test.run(self.result)
        assert '1 run, 0 failed' == self.result.summary()

    def test_failed_result_formatting(self):
        self.result.test_starting()
        self.result.test_failed("fake exception and trackback")
        assert '1 run, 1 failed' == self.result.summary()

    def test_result_failed(self):
        test = WasRun('test_failed_method')
        test.run(self.result)
        assert "1 run, 1 failed" == self.result.summary()

    def test_result_failed_during_setup(self):
        test = WasRunBadSetup('Doesnt_matter')
        test.run(self.result)
        assert "1 run, 1 failed" == self.result.summary()

    def test_summary_includes_exceptions(self):
        test = WasRun('test_failed_method')
        test.run(self.result)
        assert any("Fake Error" in e for e in self.result.exceptions())

    def test_suite(self):
        suite = TestSuite()
        suite.add(WasRun('test_method'))
        suite.add(WasRun('test_failed_method'))
        suite.run(self.result)
        assert "2 run, 1 failed" == self.result.summary()
示例#3
0
class TestCaseTest(unittest.TestCase):

	def setUp(self):
		self.result = TestResult()
		
	def testTemplateMethod(self):
		test = WasRun('testMethod')
		test.run(self.result)
		assert('setup testMethod tearDown ' == test.log)

	def testResult(self):
		test = WasRun('testMethod')
		test.run(self.result)
		assert('1 run, 0 failed' == self.result.summary())

	def testFailedResultDuringSetup(self):
		test = TestCase('testMethod')
		test.setUp = MagicMock(side_effect=Exception())
		test.run(self.result)
		assert('setup failed' == self.result.summary())

	def testFailedResultAlwaysTeardown(self):
		test = WasRun('testBrokenMethod')
		test.run(self.result)
		assert('tearDown' in test.log)

	def testFailedResult(self):
		test = WasRun('testBrokenMethod')
		test.run(self.result)
		assert('1 run, 1 failed', self.result.summary)

	def testFailedResultFormatting(self):
		self.result.testStarted()
		self.result.testFailed()
		assert('1 run, 1 failed' == self.result.summary())

	def testSuite(self):
		suite = TestSuite()
		suite.add(WasRun('testMethod'))
		suite.add(WasRun('testBrokenMethod'))
		suite.run(self.result)
		assert('2 run, 1 failed' == self.result.summary())
示例#4
0
 def test_add_result(self):
     result1 = TestResult()
     result2 = TestResult()
     result1.testStarted()
     result1.testFailed()
     result2.testStarted()
     combined_result = result1.add(result2)
     assert "2 run, 1 failed" == combined_result.summary()
示例#5
0
 def test_failed_result_formatting(self):
     result = TestResult()
     result.testStarted()
     result.testFailed()
     assert "1 run, 1 failed"
示例#6
0
 def setup(self):
     self.result = TestResult()
示例#7
0
        test.run(self.result)
        assert any("Fake Error" in e for e in self.result.exceptions())

    def test_suite(self):
        suite = TestSuite()
        suite.add(WasRun('test_method'))
        suite.add(WasRun('test_failed_method'))
        suite.run(self.result)
        assert "2 run, 1 failed" == self.result.summary()


tests = [
    'test_template_method',
    'test_result',
    'test_failed_result_formatting',
    'test_result_failed',
    'test_result_failed_during_setup',
    'test_summary_includes_exceptions',
    'test_suite',
]

ts = TestSuite()
r = TestResult()
for t in tests:
    ts.add(TestCaseTest(t))
ts.run(r)
print(r.summary())
for e in r.exceptions():
    print(e)
    print()
示例#8
0
 def setUp(self):
     self.result = TestResult()
     self.module = sys.modules[self.__module__]
示例#9
0
class TestCaseTest(TestCase):

    def setUp(self):
        self.result = TestResult()
        self.module = sys.modules[self.__module__]

    def test_template_method(self):
        test = WasRun('test_method')
        test.run(self.result)
        assert "setUp test_method tearDown " == test.log

    def test_result(self):
        test = WasRun('test_method')
        test.run(self.result)
        assert "1 run, 0 failed" == self.result.summary()

    def test_failed_result(self):
        # expected failure
        test = WasRun('broken_method')
        test.run(self.result)
        assert "1 run, 1 failed" == self.result.summary(), "Expected Failure"

    def test_failed_result_formatting(self):
        self.result.test_started()
        self.result.test_failed()
        assert "1 run, 1 failed" == self.result.summary()

    def test_get_classes_for_test(self):
        suite = TestSuite(self.module)
        test_classes = suite.get_classes_for_test()
        assert self.__class__.__name__ in test_classes.keys()
        assert isinstance(self, test_classes[self.__class__.__name__])

    def test_if_classes_for_test_are_valid(self):
        suite = TestSuite(self.module)
        test_classes = suite.get_classes_for_test()
        assert 'TestInvalidClass' not in test_classes
        assert self.__class__.__name__ in test_classes

    def test_get_methods_for_test_in_each_class(self):
        suite = TestSuite(self.module)
        methods = suite.get_class_methods(TestCaseTest)
        assert 'test_template_method' in methods
        assert 'test_get_methods_for_test_in_each_class' in methods

    def test_if_test_methods_startswith_test(self):
        suite = TestSuite()
        methods = suite.get_class_methods(TestCaseTest)
        assert 'test_if_test_methods_startswith_test' in methods
        assert '__init__' not in methods

    def test_run_suite_with_specific_class_test(self):
        suite = TestSuite(self.module, 'MockTestClass')
        suite.run(self.result)
        assert "2 run, 0 failed" == self.result.summary()

    def test_run_suite_with_specific_inexistent_class(self):
        suite = TestSuite(self.module, 'Abc')
        suite.run(self.result)
        assert "0 run, 0 failed" == self.result.summary()

    def test_run_suite_with_specific_invalid_class(self):
        suite = TestSuite(self.module, 'TestInvalidClass')
        suite.run(self.result)
        assert "0 run, 0 failed" == self.result.summary()

    def test_run_suite_with_specific_class_and_method(self):
        suite = TestSuite(self.module, 'MockTestClass', 'test_dummy_sum')
        suite.run(self.result)
        assert "1 run, 0 failed" == self.result.summary()

    def test_run_suite_with_specific_class_and_inexistent_method(self):
        suite = TestSuite(self.module, 'MockTestClass', 'inexistent_method')
        suite.run(self.result)
        assert "0 run, 0 failed" == self.result.summary()