简体   繁体   English

检查单元测试-将测试套件分为不同的文件

[英]Check Unit Test - Separating Test Suites Into Different Files

I have a small library that uses helper .c files to do various tasks for the API. 我有一个小的库,该库使用辅助.c文件来执行API的各种任务。 I would like to separate the test suites that test each component into different files. 我想将将每个组件测试到不同文件的测试套件分开。 Is there a way to do this in Check? 有没有办法在Check中执行此操作?

For instance, if I had a Money library (as in the example) I might want to write a currency conversion library test suite it in its own file (check_convert_currency.c) I might want to create, track, etc in a different test suite (check_manipulate_money.c). 例如,如果我有一个Money库(如示例中所示),我可能想在其自己的文件(check_convert_currency.c)中编写一个货币转换库测试套件,我可能想在其他测试套件中创建,跟踪等。 (check_manipulate_money.c)。 I would like to check all test suites with check_money.c. 我想使用check_money.c检查所有测试套件。

I think the best way to do this would be to create the .c files and headers for the above, include them in the check_money.c and add all test suites to the suite runner in main. 我认为最好的方法是为上述文件创建.c文件和标头,将它们包括在check_money.c中,并将所有测试套件添加到main中的套件运行器中。

I would like to do this to keep the test files readable. 我想这样做是为了保持测试文件的可读性。 If there is a better method or approach in attaining this goal, I am open to learning about it. 如果有更好的方法或方法来实现这一目标,我愿意学习。

One approach used is to have one make file for each test file. 一种使用的方法是每个测试文件都有一个make文件。 This way you will have multiple test executables for multiple aspects of the same unit under test. 这样,您将针对同一被测单元的多个方面具有多个测试可执行文件。 So you would compile with different test executable - check_convert_currency and check_manipulate_money. 因此,您将使用其他测试可执行文件进行编译-check_convert_currency和check_manipulate_money。

If you want to have the same executable for all tests then you can have header only implementations of the tests in check_manipulate_money.h and check_convert_currency.h . 如果您希望所有测试都具有相同的可执行文件,则可以在check_manipulate_money.h和check_convert_currency.h中具有测试的仅标头实现。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM