나는 꽤 일반적인 질문이되기를 바랍니다. XML 파일을 테스트하고 특정 태그의 유효성을 검사합니다. 태그 검사 코드를 재사용하려고하므로 각 필드의 코드를 다시 작성하고 싶지 않습니다. 그러나 이렇게하려고 할 때python 테스트 케이스 클래스를 재사용하는 방법
여기 UnitTest Framework를 사용하려고하는 "ValidateField"클래스가 있습니다. 사용하려고 시도하는 코드입니다. 나는 단순히 다음과 같이 그것을 호출하려고 노력하고있다. 내가 얻은 것은 유닛 테스트 프레임 워크가 0 테스트를 실행했다는 것입니다. 나는 클래스 내에서 재사용을 시도하지 않고있는 유닛 테스트 프레임 워크를 다른 곳에서 성공적으로 사용하고있다. 지금 내가 누락 된 곳이면 누구나? 여기
출력 내가 얻을 수있다 : 여기
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
----------------------------------------------------------------------
내가 재사용 가능한 클래스가 사용하는 재사용 가능한 클래스 다음
import Common.ValidateField
class Tests():
def test_testCreated(self):
validate = Common.ValidateField.ValidateField()
validate.test_field('./created')
로 통화를하고있는 클래스/메소드입니다 단위 테스트 프레임 워크.
import unittest
import Main
import Common.Logger
class ValidateField(unittest.TestCase):
def test_field(self, xpath):
driver = Main.ValidateDriver().driver
logger = Common.Logger.Logger
tag = []
for t in driver.findall("'" + xpath + "'"):
tag.append(t)
# Test to see if there is more than one tag.
if len(tag) > 1:
self.assertTrue(False, logger.failed("There is more than one " + "'" + t.text + "'" + " tag."))
else:
# Test for a missing tag.
if len(tag) <= 0:
self.assertTrue(False, logger.failed("There is no " + "'" + t.text + "'" + " tag."))
# Found the correct number of tags.
self.assertTrue(True, logger.passed("There is only one " + "'" + t.text + "'" + " tag."))
# Test to make sure there is actually something in the tag.
if t.text is None:
self.assertTrue(False, logger.failed("There is a " + "'" + t.text + "'" + " tag, but no value exists"))
테스트를 어떻게 실행하고 있습니까 (이 경우에는 실행하지 않고 있습니까)? – geoffspear