source: unitpy/test/RunWithTest.py

Last change on this file was 1040, checked in by wouter, 2 months ago

#303 added 2 tests with actual test run

File size: 1.6 KB
Line 
1import random
2from unitpy.GeneralTests import GeneralTests
3from typing import List
4from pickle import TRUE
5from unitpy.Before import Before, getBefore
6from unitpy.RunWith import RunWith, getRunWith
7from unitpy.Runner import JUnit4ClassRunner, Parameterized, runTests
8from unitpy.Test import Test
9from unittest import TestCase
10
11class Clazz1:
12 '''
13 Bugged, it always returns the same hashcode.
14 '''
15 def __init__(self, v:str):
16 self.value = v
17
18 def __repr__(self):
19 return str(self.value) + " " + str(random.randint(1,100))
20
21
22
23 def __hash__(self):
24 return hash(self.value)
25
26 def __eq__(self, other):
27 return isinstance(other, self.__class__) and \
28 self.value == other.value
29
30@RunWith(JUnit4ClassRunner)
31class Clazz2(Clazz1):
32 @Before()
33 def initialize(self):
34 return "ok"
35
36
37
38@RunWith(Parameterized)
39class Clazz3(Clazz1):
40 def initialize(self):
41 return "ok"
42
43
44@RunWith(JUnit4ClassRunner)
45class SomeRunnableTests:
46 @Test()
47 def tryassert(self):
48 TestCase().assertTrue(1==1)
49 print("assert is ok")
50 @Test(expected = ArithmeticError)
51 def divzero(self):
52 1/0
53
54
55class RunWithTest(TestCase):
56 def test1(self):
57 self.assertEqual(JUnit4ClassRunner, getRunWith(Clazz1))
58
59 def test2(self):
60 self.assertEqual(JUnit4ClassRunner, getRunWith(Clazz2))
61
62 def test3(self):
63 self.assertEqual(Parameterized, getRunWith(Clazz3))
64
65 def testRun(self):
66 runTests(SomeRunnableTests)
67 print("testruns ok")
68
69
70
71
72
Note: See TracBrowser for help on using the repository browser.