CppUnit - Registry multiple suites to be runned in a single main function
<p>I am starting with C++ unit tests using CppUnit. The goal I am trying to achieve is to run all my test suites on a single main file (and function). Let me explain:</p>

<p>Let's say we have two classes with test for two C++ classes I have designed:</p>

<pre><code>#ifndef FIRSTCLASSTEST_H
#define FIRSTCLASSTEST_H

class FirstClassTest : public CppUnit::TestFixture {

  CPPUNIT_TEST_SUITE( FirstClassTest );
  CPPUNIT_TEST( testConstructor );
  CPPUNIT_TEST_SUITE_END();

public:
  void setUp(void);
  void tearDown(void);
protected:
  void testConstructor(void);
};

#endif
</code></pre>

<p>And let the other class be similar:</p>

<pre><code>#ifndef SECONDCLASSTEST_H
#define SECONDCLASSTEST_H

class SecondClassTest : public CppUnit::TestFixture {

  CPPUNIT_TEST_SUITE( SecondClassTest );
  CPPUNIT_TEST( testConstructor );
  CPPUNIT_TEST_SUITE_END();

public:
  void setUp(void);
  void tearDown(void);
protected:
  void testConstructor(void);
};

#endif
</code></pre>

<p>And the cpp files look similar to:</p>

<pre><code>#include "FirstClassTest.h"

CPPUNIT_REGISTRY_ADD_TO_DEFAULT( FirstClassTest );

void FirstClassTest::setUp(){
   //setup...
}

void FirstClassTest::tearDown(){
  //teardown...
}

void FirstClassTest::testConstructor(){
   //some asserts
}
</code></pre>

<p>After these files (Which work properly individually), I want to create a unique file to run all my registered suites. Let's say my main test runner is AllTest.cpp:</p>

<pre><code>#include &lt;cppunit/TestResult.h&gt;
#include &lt;cppunit/TestResultCollector.h&gt;
#include &lt;cppunit/BriefTestProgressListener.h&gt;
#include &lt;cppunit/TestRunner.h&gt;
#include &lt;cppunit/CompilerOutputter.h&gt;
#include &lt;cppunit/extensions/HelperMacros.h&gt;

//Include Test classes here
#include "FirstClassTest.cpp"
#include "SecondClassTest.cpp"

int main()
{
  // informs test-listener about testresults
  CPPUNIT_NS::TestResult testresult;
  // register listener for collecting the test-results
  CPPUNIT_NS::TestResultCollector collectedresults;
  testresult.addListener (&amp;collectedresults);

  // register listener for per-test progress output
  CPPUNIT_NS::BriefTestProgressListener progress;
  testresult.addListener (&amp;progress);

  // insert test-suite at test-runner by registry
  CPPUNIT_NS::TestRunner testrunner;
  testrunner.addTest (CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest ());
  testrunner.run(testresult);

  // output results in compiler-format
  CPPUNIT_NS::CompilerOutputter compileroutputter(&amp;collectedresults, std::cerr);
  compileroutputter.write ();

  // return 0 if tests were successful
  return collectedresults.wasSuccessful() ? 0 : 1;

}
</code></pre>

<p>But this does not work. How can I achieve the desired behavior? I have checked the docs: <a href="http://cppunit.sourceforge.net/doc/cvs/class_auto_register_suite.html" rel="nofollow noreferrer">http://cppunit.sourceforge.net/doc/cvs/class_auto_register_suite.html</a> but without success. </p>

<p>I suspect the main problem is in the AllTests.cpp and I am not adding the suites properly to the registry or to the testRunner.</p>

<p>Any help would be appreciated. 
Cheers.</p>

<p><strong>SOLUTION EDIT:</strong> Finally, and thanks to the <a href="https://cgit.freedesktop.org/libreoffice/cppunit/tree/examples/hierarchy?h=cppunit-1-13" rel="nofollow noreferrer">examples</a> and advices provided by @moggi, I have been able to resolve my problem. I have removed any <code>CPP_UNIT_SUITE_REGISTRATION</code> from my cpp files and I have modified the AllTest.cpp main function to be like this:</p>

<pre><code>int main()
{
  // informs test-listener about testresults
  CPPUNIT_NS::TestResult testresult;
  // register listener for collecting the test-results
  CPPUNIT_NS::TestResultCollector collectedresults;
  testresult.addListener (&amp;collectedresults);

  // register listener for per-test progress output
  CPPUNIT_NS::BriefTestProgressListener progress;
  testresult.addListener (&amp;progress);

  // insert test-suite at test-runner by registry
  CPPUNIT_NS::TestRunner testrunner;

  // MODIFIED PART, TEST SUITES ADDED MANUALLY
  testrunner.addTest( FirstClassTest::suite() );
  testrunner.addTest( SecondClassTest::suite() );

  testrunner.run(testresult);

  // output results in compiler-format
  CPPUNIT_NS::CompilerOutputter compileroutputter(&amp;collectedresults, std::cerr);
  compileroutputter.write ();

  // return 0 if tests were successful
  return collectedresults.wasSuccessful() ? 0 : 1;

}
</code></pre>