摘要:
迭代测试边界条件Testing corner cases by iterationWhile developing code, new corner case inputs are often discovered. Being able to capturethese inputs in an iterable array makes it easy to add related test methods.1. Create a new file called recipe10.py in which to put all our code for this recipe.2. Pick a 阅读全文
摘要:
测试边界条件Testing the edgesWhen we write automated tests, we pick the inputs and assert the expected outputs. It isimportant to test the limits of the inputs to make sure our code can handle good and badinputs. This is also known as testing corner cases.1. Create a new file named recipe9.py in which to 阅读全文
摘要:
将晦涩难懂的测试分解成简单的测试本篇的目的是解说晦涩的测试不易一目了然,然后用一个例子将晦涩的测试用例化为简单的测试用例,使得测试结果一目了然。Breaking down obscure tests into simple ones.Unittest provides the means to test the code through a series of assertions. I have often feltthe temptation to exercise many aspects of a particular piece of code within a single tes 阅读全文
摘要:
重组旧的测试代码,使用场景,之前有一段未使用unittest的测试代码,通过另一个包装文件使其运作起来,日常生活中极少用到。Retooling old test code to run inside unittest.Sometimes, we may have developed demo code to exercise our system. We don't have torewrite it to run it inside unittest. Instead, it is easy to hook it up to the test framework and runit 阅读全文
摘要:
在测试模块中定义测试套件Defining test suites inside the test module.Each test module can provide one or more methods that define a different test suite. Onemethod can exercise all the tests in a given module; another method can define a particularsubset.1. Create a new file called recipe6.py in which to put our 阅读全文
摘要:
执行多个测试套件(suites)Chaining together a suite of testsUnittest makes it easy to chain together test cases into a TestSuite. A TestSuite can be runjust like a TestCase, but it also provides additional functionality to add a single test, multipletests, and count them.1. Create a new file named recipe5.py 阅读全文
摘要:
根据不同的命令行参数进行不同代码的单元测试。Running a subset of test case methodsSometimes it's convenient to run only a subset of test methods in a given test case. This recipewill show how to run either the whole test case, or pick a subset from the command line.1. Create a new file named recipe4.py in which to put 阅读全文
摘要:
Running test cases from the command line with increased verbosity.It is easy to adjust the test runner to print out every test method as it is run.1. Create a new file called recipe3.py in which to store this recipe's code.2. Pick a class to test. In this case, we will use our Roman numeral conv 阅读全文
摘要:
Setting up and tearing down a test harness.With the following steps, we will setup and teardown a test harness for each test method.1. Create a new file called recipe2.py in which to put all our code for this recipe.2. Pick a class to test. In this case, we will use a slightly altered version of our 阅读全文
摘要:
一个非常简单的python的测试用例,取自电子书:《Python Testing Cookbook》第一章内容,里面说的足够简单明了,将之摘出来,对照代码,应该很容易理解。 The basic concept of an automated unittest test case is to instantiate part of our code, subject it to operations... 阅读全文