GenCxxTest


GenCxxTest is an open source Bouml plugout to generate CxxTest test cases and test fixtures for a class or group of classes in a class view.

Features

This plug-out generates the following CxxTest elements: - This plug out also generates a suitable source artifact (called "AllTests") containing all the generated test classes and fixtures if a deployment view was selected on the dialog box (see screenshot below).

GenCxxTestCase screenshot

Applies To

This plugout can be applied to a class, enum(a UML class with "enum" stereotype) and Class View in a Bouml model.If applied to a class view, it generates test case classes for all the classes in the selected class view. See below for description of how test classes are generated for every class.

Generating Test Suites, Enum Traits and Test Fixtures

If applied to a class, it generates another class (i.e. a test suite) whose name starts with "Test". This new class contains a test method for every public method of the class to be tested (execpt the destructor). The name of the test methods begin with "test".

If this plugout is applied more than once on a class, the method bodies of the test class are preserved.

If applied to an enum (i.e. a class in the browser with "enum" stereotype), it generates CxxTest Enumeration Traits for it and associates it with the AllTests artifact.

If applied to a class view, the plugout generates test suites for all classes in the class view. The dialog box is shown only once. The selections on the dialog box apply to all the classes to be generated.

Test Methods for Overloaded Operators in a Class

The names of any operators overloaded by a class are generated in a special way. These names still start with the "test" word as required by CxxTest. Here is a table showing the operator name and its corresponding test method name generated.

Overloaded Operator Test Method Generated
operator=testOperatorAssignment
operator==testOperatorEqual
operator<testOperatorLess
operator>testOperatorGreater
operator<=testOperatorLessOrEqual
operator>=testOperatorGreaterOrEqual
operator!=testOperatorNotEqual
operator+testOperatorPlus
operator-testOperatorMinus
operator*testOperatorMultiply
operator/testOperatorDivide
operator%testOperatorMod
operator+=testOperatorPlusAssign
operator-=testOperatorMinusAssign
operator*=testOperatorMulAssign
operator/=testOperatorDivAssign
operator%=testOperatorModAssign
operator>>testOperatorRightShift
operator<<testOperatorLeftShift
operator>>=testOperatorRightShiftAssign
operator<<=testOperatorLeftShiftAssign
operator()testOperatorCall
operator[]testOperatorSubscript
operator^testOperatorPower
operator^=testOperatorPowerAssign
operator&testOperatorBitwiseAnd
operator&=testOperatorBitwiseAndAssign
operator|testOperatorBitwiseOr
operator|=testOperatorBitwiseOrAssign
operator~testOperatorBitwiseNot
operator~=testOperatorBitwiseNotAssign
operator&&testOperatorLogicalAnd
operator&&=testOperatorLogicalAndAssign
operator||testOperatorLogicalOr
operator||=testOperatorLogicalOrAssign
operator++testOperatorIncrement
operator--testOperatorDecrement
operator->testOperatorMemberAccessViaPtr
operator->*testOperatorPtrMemberAccessViaPtr
operator newtestOperatorNew
operator new[]testOperatorNewArray
operator deletetestOperatorDelete
operator delete[]testOperatorDeleteArray

Generating Global and World Fixtures

If applied to a class view with 'gf' argument, this plugout can generate CxxTest global and world fixtures (See Bouml Tool Setting below).

GenCxxTestCase screenshot

In order to generate World Fixture, check the "Generate World Fixture" checkbox on the dialog box above. If this checkbox is unchecked, only a global fixture will be generated.

The global fixture classes are named as 'GlobalFixtureN' and the world fixtures are named 'WorldFixtureN', where N=1,2,3 and so on

NOTE: The property GlobalFixtureSuffix in the root package (i.e. Project package) holds the number to be suffixed to the next global/world fixture.

The AllTests Artifact

All the test classes (i.e. test suites, fixtures enum traits etc) are automatically associated with the AllTests artifact. This artifact contains a custom definition suitable for CxxTest generator script.

If this artifact already exists, when new test suites or fixtures etc. are generated, they will automatically be added to the existing AllTests artifact and the definition of this artifact will also be updated accordingly.

It is possible to generate different AllTests artifacts in different deployment views just be selecting a different deployment view on the dialog box. This way you can (If you really want) keep test suites of different areas of your code separate. Note however, that there can be only one AllTests artifact in a deployment view and it is easier to just add all the test classes to one artifact and run all tests together.

NOTE: The AllTests artifact only generates a .h file (because .cpp file is not needed by CxxTest).

Bouml Tool Setting

This plugout can be configured in Bouml in two ways.

Build and Install

  1. Uncompress the downloaded archive into a folder.
  2. Open the cxxtest.prj file using Bouml. Set the generation directory for C++ in the Bouml generation settings. Generate C++ source code and apply "Generate .pro" plug-out on the 'executable' artifact in the "API USER Deployment View".
  3. Change to the folder where the C++ source (and .pro file) has been generated by Bouml
  4. Generate make file by using the "qmake gencxxtest.pro" command on linux/unix or use tmake on windows.
  5. Copy the executable 'gencxxtest' (or 'gencxxtest.exe' in windows) to the Bouml directory
  6. Configure Bouml to use the plugout for class and class view items as discribed above.

Executable

The plugout executable is named gencxxtest.

Version

See the file CHANGES.TXT for latest features added to the current version and change history.

Contact

You can send queries, bug reports, feature requests etc to my email: sulemankm2 at yahoo dot com.

License

This software is distributed under the GNU GPL license and all standard disclaimers apply.