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:
class ExampleTest : public cfixcc::TestFixture
CFIXCC_BEGIN_CLASS( ExampleTest )
CFIXCC_METHOD( TestOne )
CFIXCC_METHOD( TestTwo )
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:
const wchar_t* testString = L"test";
// Use typesafe assertions...
CFIXCC_ASSERT_EQUALS( 1, 1 );
CFIXCC_ASSERT_EQUALS( L"test", testString );
CFIXCC_ASSERT_EQUALS( wcslen( testString ), ( size_t ) 4 );
// ...log messages...
CFIX_LOG( L"Test string is %s", testString );
// ...or use the existing "C" assertions.
CFIX_ASSERT( wcslen( testString ) == 4 );
CFIX_ASSERT_MESSAGE( 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.