Defining test dependencies in CppUnit?

I would like to indicate the testing order in CppUnit. According to my research, the order of testing depends on either the compiler or the linker, and how they came across the files.

How to define dependencies in CppUnit?

For example, consider a rectangle class that has four lines. Each row contains two point classes. Suppose each class is in a separate translation module or block.

struct Point { int x; int y; }; struct Line { Point a; Point b; }; struct Rectangle { Line top; Line left; Line right; Line bottom; }; 

In the above code, the Point class must first be checked, then the Line class, and finally the Rectangle class. There is no reason to check the Rectangle class if the Line or Point classes have problems. This is a very simplified example.

For compound classes, inner classes or member data type classes must first be checked.

Suppose each class has a testing class associated with it. Each test class has its own published test methods (which are registered in the CppUnit list), in separate files. Class for testing Lines does not know the testing class for points; and similarly for a rectangle. When these test classes are compiled, their order depends on the compiler and linker.

So how to organize test cases?

FYI, I am using CppUnit, wxTestRunner and Visual Studio 2008

+4
source share
1 answer

What you are trying to do is not unit testing. Pure unit testing is designed to test individual units (individual classes) using bullying or fake objects instead of real dependencies; as soon as you test dependencies on each other, this is integration testing, not unit testing.

Subject to this disclaimer ...

It seems that you can use CPPUNIT_TEST_SUITE_NAMED_REGISTRATION to create several sets, and then run each set in order only if all the previous suites are available but you may need to hack or replace the wxTestRunner test runner to do this.

The CppUnit page on Creating TestSuite has other options for registering test suites; CPPUNIT_REGISTRY_ADD , for example, allows you to create a hierarchy of sets, which should give you some control over the order, but I do not see any way to refuse in the same set to cancel subsequent tests.

Finally, as is speculation, CppUnit is probably not the best C ++ module testing platform these days. I personally am a fan of Google Test , but Boost.Test and UnitTest ++ are also good. ( This answer presents a personalized Saru project that sounds like it can give you the flexibility you want to order tests.)

+5
source

Source: https://habr.com/ru/post/1313235/


All Articles