简体   繁体   中英

Could a c++ obj file be unit tested?

It appears to me that each c++ class code file is compiled into its own obj file. And the other header files look like the interface requirements for an "inversion of control".

So, could a c++ obj file be linked to unit test and tested using mocking of those headers without the other obj files project ?

Disclaimer, I work in Typemock.

With Typemock Isolator++ you can mock almost everything directly from your production code, by linking your dll or exe to the unit-test project. You can use header-files as well. We have similar enviroment for c#/.net projects, and both are really easy to work with.

Take a look !

In theory, yes, but it would be a significant pain to set up. When you create the object file you promise that a certain environment will be available for the generated code to exist in. Attempting to then use it without that environment will be difficult; you'll need to provide at least enough of it to allow all linktime dependencies to be satisfied.

Doing so for each object file would be a lot of work, far more work then adding some kind of testing rig to the program as a whole.

BTW, it's not true that each class gets its own object file. Object files correspond to translation units, and contain a mixture of variables, functions, classes, etc., and if link-time code generation is enabled, it may not even be machine code but some intermediate representation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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