nose2 this automation tool asked me to write the code twice as fast (two)

Previous article describes a simple to use nose2, please refer to: nose2 this automation tool asked me to write the code twice as fast.

And this one is the introduction nose2 of some advanced features.

The method of preparation of test cases

The difference is that the unittest, nose2 the test does not have to exist as a class, the function may be used. Any functions and classes, as long as the names match certain conditions (e.g., test beginning or ending test, etc.), is automatically recognized as a test case.

to parameterize

Unittest module is similar among ddt, but simple to use than the ddt module. Among the test process, there is usually a plurality of sets of data of test cases, multiple sets of test cases to test a common method to achieve data-driven. In nose2 which you can use:

1, @params (* test_data) receives a plurality of sets of test data passed in the outside;

2, test_add among (data) data each time a set of data extraction operation, thus, data is actually { "data": (1, 2), "expected": 3} Such a set of data.

3, because here there are three sets of data, so the running time will be three test cases.

Test Fixture

Test fixture in order to prepare test preconditions and post-conditions.

@with_setup (before_test) represent pre-conditions before executing the test cases to be executed

@with_teardown (after_test) after postcondition represents the test case execution

before_test and after_test is a function of their definition

nose2 vs unittest

nose2 be simpler to use than unittest.

Use unittest, need to master the basic concepts testrunner, testsuite, testcase, etc., also need to be familiar with classes and objects. nose2 hides the details of the design, the difficulty will be lower.

nose2 can run unittest test can seamlessly switch.

But not to say that unittest bad. unittest as a python standard library, and python version binding, very stable, do not worry about compatibility issues.

If you want to learn a unit testing framework, unittest advice from the start, because you can come into contact with loader, suite, such components runner, testing framework for understanding more helpful, after a good unittest learn, or relearn nose2 pytest this more advanced framework , can effectively improve programming efficiency.

nose2 vs pytest

If you just want to learn a high-level unit testing framework, I suggest you learn pytest, rather than nose2.

nose2 good enough, even his design looks more clear than pytest, easier to understand. But the community does not pytest active, so people use is relatively small.

In fact, nose2 and pytest usage many of which are very similar, a study, another can easily get started. nose2 to deepen the understanding of the testing framework have great benefits, it is recommended python automated test engineers are aware of at nose2.

Description: This is the original lemon classes rain Ze teacher, Reprinted indicate the source.

100G receive test data

Make it easier to learn software testing!

Today's share went to here

If you have questions about this article?

Message in the message area quickly it ~

Published an original article · won praise 0 · Views 9

Guess you like

Origin blog.csdn.net/ningmengban1/article/details/104270673