cfix 1.2 introduces improved C++ support

cfix 1.2, which has been released today, introduces a number of new features, the most prominent being improved support for C++ and additional execution options.

New C++ API

To date, cfix has primarily focussed on C as the programming language to write unit tests in. Although C++ has always been supported, cfix has not made use of the additional capabilities C++ provides. With version 1.2, cfix makes C++ a first class citizen and introduces an additional API that leverages the benefits of C++ and allows writing test cases in a more convenient manner.

Being implemented on top of the existing C API, the C++ API is not a replacement, but rather an addition to the existing API set.

As the following example suggests, fixtures can now be written as classes, with test cases being implemented as methods:

    #include <cfixcc.h>
    class ExampleTest : public <a href="" title="TestFixture">cfixcc::TestFixture</a>
      void TestOne() 
      void TestTwo() 
    <a href="" title="CFIXCC_BEGIN_CLASS">CFIXCC_BEGIN_CLASS</a>( ExampleTest )
      <a href="" title="CFIXCC_METHOD">CFIXCC_METHOD</a>( TestOne )
      <a href="" title="CFIXCC_METHOD">CFIXCC_METHOD</a>( TestTwo )
    <a href="" title="CFIXCC_END_CLASS">CFIXCC_END_CLASS</a>()

To learn more about the definition of fixtures, have a look at the respective TestFixture chapter in the cfix documentation.

Regarding the implementation of test cases, cfix adds a new set of type-safe, template-driven assertions that, for instance, allow convenient equality checks:

    void TestOne() 
      const wchar_t* testString = L"test";
      // Use typesafe assertions...
      <a href="" title="CFIXCC_ASSERT_EQUALS">CFIXCC_ASSERT_EQUALS</a>( 1, 1 );
      <a href="" title="CFIXCC_ASSERT_EQUALS">CFIXCC_ASSERT_EQUALS</a>( L"test", testString );
      <a href="" title="CFIXCC_ASSERT_EQUALS">CFIXCC_ASSERT_EQUALS</a>( wcslen( testString ), ( size_t ) 4 );
      // ...log messages...
      <a href="" title="">CFIX_LOG</a>( L"Test string is %s", testString );
      // ...or use the existing "C" assertions.
      <a href="" title="CFIX_ASSERT">CFIX_ASSERT</a>( wcslen( testString ) == 4 );
      <a href="" title="CFIX_ASSERT_MESSAGE">CFIX_ASSERT_MESSAGE</a>( testString[ 0 ] == 't', 
        L"Test string should start with a 't'" );

Again, have a look at the updated API reference for an overview of the new API additions.

Customizing Test Runs

Another important new feature is the addition of the new switches -fsf (Shortcut Fixture), -fsr (Shortcut Run), and -fss (Shortcut Run On Failing Setup). Using these switches allows you to specify how a test run should resume when a test case fails.

When a test case fails, the default behavior of cfix is to report the failure, and resume at the next test case. By specifying -fsf, however, the remaining test cases of the same fixture will be skipped and execution resumes at the next fixture. With -fsr, cfix can be requirested to abort the entire run as soon as a single test case fails.

What else is new in 1.2?


As always, cfix 1.2 is source and binary compatible to previous versions. The new MSI package and source code can now be downloaded on Sourceforge.

cfix is open source and licensed under the GNU Lesser General Public License.

« Back to home