CppUnit "OK (0 tests)"

Help
Touki
2011-03-16
2013-04-22
  • Touki
    Touki
    2011-03-16

    Hi,

    Everything is compiling on my code, but the console print : "OK (0 tests)" when I launch the executable.

    I'm compiling with : g++ mainTest.cpp -lcppunit -o test

    Here is my main.cpp
    #include </usr/include/cppunit/extensions/HelperMacros.h>
    #include </usr/include/cppunit/extensions/TestFactoryRegistry.h>
    #include </usr/include/cppunit/ui/text/TestRunner.h>

    #include "BankTest.hpp"

    using namespace std;

    int main()
    {
      CppUnit::TextUi::TestRunner runner;
      CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
      runner.addTest(suite);
      bool wasSuccessful = runner.run();
      return wasSuccessful;
    }

    If u need, here is my Test.hpp :
    #ifndef BANKTEST_HPP
    #define BANKTEST_HPP

    #include </usr/include/cppunit/TestFixture.h>
    #include </usr/include/cppunit/extensions/HelperMacros.h>

    #include "../SOURCES/Headquarter.hpp"

    using namespace std;

    class BankTest : public CppUnit::TestFixture{
    CPPUNIT_TEST_SUITE(BankTest);
    CPPUNIT_TEST(testGetBalance);
    CPPUNIT_TEST(testWithdraw);
    CPPUNIT_TEST(testDeposit);
    CPPUNIT_TEST_SUITE_END();

    public:
    void setUp();
    void tearDown();
    void testGetBalance();
    void testWithdraw();
    void testDeposit();

    private:
    Bank bk1, bk2;
    };

    #endif /*BankTest*/

    Here is my bankTest.cpp :
    #include </usr/include/cppunit/extensions/HelperMacros.h>
    #include "BankTest.hpp"

    CPPUNIT_TEST_SUITE_REGISTRATION(BankTest);

    using namespace std;

    void BankTest::setUp()
    {
    this->bk1 = Bank(0);
    this->bk2 = Bank(0);
    }

    void BankTest::tearDown()
    {

    }

    void BankTest::testGetBalance()
    {
    CPPUNIT_ASSERT(this->bk1.getBalance() == 0);
    }

    void BankTest::testDeposit()
    {
    int v = this->bk1.getBalance();
    this->bk1.deposit(500);
    CPPUNIT_ASSERT(bk1.getBalance() == (v+500));
    }

    void BankTest::testWithdraw()
    {
    this->bk1.withdraw(this->bk1.getBalance())
    this->bk1.deposit(500);
    CPPUNIT_ASSERT(bk1.withdraw(200));
    CPPUNIT_ASSERT(!(bk1.withdraw(10000)));
    }

    Thanks in advance

     
  • stevenhuang
    stevenhuang
    2012-06-14

    I also met this question. I don't know why?