Unit testing - some issues related to code organization in c++ testing
ringa_lee
ringa_lee 2017-05-31 10:38:53
0
1
881

I am a novice c programmer. I used JavaScript most of the time. Now due to homework needs, I am writing a project in c. The development environment is Xcode. I want to do the tests myself, but I have no knowledge about testing before. As far as I know, after reading this, I decided to use the catch testing framework.

When I was writing a small C job before, I either cout<< directly in the main function and then deleted it before submitting, or I created a new cpp file, added the main function, and then added the main function in the project Temporarily change the name (usually I change the main function name to main00 or the like), click Run in XCode to temporarily test it, mainly to test the uncertainty in a certain place, and then change it back after the test is completed.

But I think the methods listed above are really stupid and make all seniors laugh.

Now my project directory is like this (this is a job to implement minisql in c):

Currently, each file actually has no content. Each folder represents a module. The relationship between each module is as follows:

I plan to write one part and test one part (for example, write BufferManager first). If there is no problem in the test, continue to write the next part.

So now I have the following questions about the organization of test files:

Should I put the test files in the corresponding module file directory? Or is there a separate test file?

Should each module have a separate test file?

In addition, I found that if I write two test files, even if I comment out #define CATCH_CONFIG_MAIN, this still cannot run normally unless all other test files are commented out.

In addition, after I write the entry file (there is a main function in NewSQL.cpp), how should I run these test files? Are you still commenting and uncommenting....

I feel like the question I asked is a bit too stupid, but I really want to know how to write and use the correct test. I couldn’t find a very targeted answer on the Internet, so I came here to ask, thank you~

(If you think something is not done well, please point it out and I will seriously correct it, but please do not attack personally. If your answer is very valuable for reference, I will also send you a private message to ask if you need a certain amount of red envelope remuneration. Student Party, let’s express our feelings)

Attached catch portal: https://github.com/philsquare...

ringa_lee
ringa_lee

ringa_lee

reply all(1)
给我你的怀抱

Should I put the test files in the corresponding module file directory? Or is there a separate test file?

Should each module have a separate test file?

In addition, I found that if I write two test files, even if I comment out #define
CATCH_CONFIG_MAIN, it still cannot run normally unless all other test files are commented out.

In addition, after I have written the entry file (there is a main function in NewSQL.cpp), how should I run these test files? Are you still commenting and uncommenting....

Test code and production code are separated and related in naming
For example, the test class of class A is called AUnitTest or ATest or AUT

The test files of each module are separated

The test file has its own entry file

The key is project configuration. The test project depends on the production code, and the production code does not depend on the test code.
Two should be able to produce two executable programs. Configure the project according to such goals

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template