定义一个鼻子测试类'TestingCircleCreation',它使用下面指定的四个测试来测试'init'方法的行为。
3.定义一个鼻子测试方法'test_creating_circle_with_greaterthan_radius',它检查是否引发了ValueError异常,并显示错误消息“radius必须介于0和1000之间”,同时创建半径为1000.1的圆
我没有得到预期的输出。请建议
使用的代码:
class TestCircleCreation(unittest.TestCase):
def test_creating_circle_with_numeric_radius(self):
c1=Circle(2.5)
self.assert_equal(c1.radius,2.5)
def test_creating_circle_with_negative_radius(self):
c1=Circle(2.5)
self.assert_equal(c1.radius,2.5)
self.assert_raises(ValueError, Circle, -2.5)
def test_creating_circle_with_greaterthan_radius(self):
c1=Circle(2.5)
self.assert_equal(c1.radius,2.5)
self.assert_raises(ValueError, Circle, 1000.1)
def test_creating_circle_with_nonnumeric_radius(self):
c1=Circle(2.5)
self.assert_equal(c1.radius,2.5)
self.assert_raises(TypeError, Circle, 'hello')
class TestingCircleCreation:
def test_creating_circle_with_numeric_radius(self):
c1=Circle(2.5)
assert c1.radius==2.5
def test_creating_circle_with_negative_radius(self):
c1=Circle(2.5)
assert c1.radius==2.5
with assert_raises(ValueError):
Circle(-2.5)
def test_creating_circle_with_greaterthan_radius(self):
c1=Circle(2.5)
assert c1.radius==2.5
with assert_raises(ValueError):
Circle(1000.1)
def test_creating_circle_with_nonnumeric_radius(self):
c1=Circle(2.5)
assert c1.radius==2.5
with assert_raises(TypeError):
Circle('hello')