Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCUnit and C++ in Xcode 4?

Is anybody using OCUnit (as in Xcode 4.2 Unit Testing) with C++ code successfully?

After hours trying to understand what's going on I'm now pretty convinced there are some major flaws in using Xcode 4 and OCUnit to test C++ code from Objective-C++ files (.mm)

The main application (Cocoa with some C++ business logic) compiles fine! The trivial .mm test class fails with weird compiler errors, varying between

  • Use of undeclared identifier (C++ class name)
  • Use of incomplete type
  • C++ requires a type specifier for all declarations

and so forth. Basically it seems to be terribly confused with the C++ bits. The classes the test files complain about compile JUST FINE from the main application! They can be instantiated in the main application JUST FINE.

Anybody having encountered and solved this before?

Thanks, Jay

like image 453
Jay Avatar asked Oct 24 '22 16:10

Jay


1 Answers

When I unit tested C++ code with OCUnit, I had to make the C++ implementation files members of the unit test target to get unit tests to work. Select a C++ file from the project navigator and open the file inspector. There should be a Target Membership section in the file inspector. The Target Membership section has a list of your project's targets with a checkbox next to each target. Select the checkbox next to the unit test target to make the file a member of the unit test target.

like image 66
Swift Dev Journal Avatar answered Nov 15 '22 08:11

Swift Dev Journal