OOP C++ Setup
OOP C++ Setup
!
Object Oriented Programming
C++ Setup: Installing Netbeans, GNU Compilers, and CppUnit
!
Please read through this entire guide once before starting.
The steps that you follow will depend on which operating system you are using.
!
This guide is divided into the following sections:
Installing Netbeans and the GNU Compiler Collection 2
#include <iostream>
using namespace std;
!
5. In the Rover project that is currently open in Netbeans, create a CppUnit Test
■ select File -> New File.
■ At Step 1. Choose File Type
• under Categories select C/C++ Tests
• under File Types select CppUnit Test
■ In the New CppUnit Test pop-up window, create a test named RoverTest with a test
class named TestRover and a test runner file named test_rover.cpp.
Be sure to set Folder to an empty string. The default is to create a sub-folder named tests;
however, this causes trouble down the road. Your NewCppUnit Test pop-up window
!
6. Try to build by selecting Run -> Test Project (or Ctrl-F6).
On Mac OS, the build will most likely fail; the log should include an error message like
This can be fixed by opening a Terminal and creating a symbolic between the location
where homebrew installed CppUnit and the location where Netbeans expects to find it:
If the build succeeds, then you should see that one out of the two tests failed.
You are now ready to go!
! Page 3 of 4
Object Oriented Programming! Laboratory 7
class TestRover
{
public:
void testAttach ();
}
"
2. Wherever you need to use CPPUNIT_ASSERT, simply use the C language built-in
assert function; e.g.
#include <assert.h>
!
[...]
!
!
void TestRover::testAttach()
{
[...]
assert( rover->deviceCount() == 1 );
}
"
3. To run the unit tests, simply create another executable (i.e. a source code file that defines
the main() function) and use it to call the methods of the unit testing class; e.g.
#include “TestRover.h”
!
int main ()
{
TestRover* test = new TestRover;
test->testAttach ();
[...]
cout << “All unit tests completed successfully” << endl;
return 0;
}
"
! Page 4 of 4