3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CXX=g++LIBS=-lcppunit
SOURCES=someTest.cc some.ccTARGETS=mainTestall :    g++ -o mainTest mainTest.cc $(SOURCES) $(LIBS)clean :   rm $(TARGET)

CPPUnitを使う上で必要なファイル
- mainTest.cc: メインのテストコードここはテンプレで良さそう
- someTest.cc: 自分のテストコードを書く場所
- some.cc: テスト対象となるコードやクラス

mainTest.cc
#include <cppunit/TestResult.h>#include <cppunit/TestResultCollector.h>#include <cppunit/BriefTestProgressListener.h>#include <cppunit/TestRunner.h>#include <cppunit/extensions/TestFactoryRegistry.h>#include <cppunit/CompilerOutputter.h>using namespace CPPUNIT_NS;int main(int argc, char **argv) {   TestResult controller;  TestResultCollector result; controller.addListener(&result);        BriefTestProgressListener progress; controller.addListener(&progress);      TestRunner runner;  runner.addTest(TestFactoryRegistry::getRegistry().makeTest());  runner.run(controller);     CompilerOutputter outputter(&result, stdCOut());    outputter.write();      return result.wasSuccessful() ? 0 : 1;}

これはこのままで良さそう

someTest.cc
#include "some.cc"#include <cppunit/extensions/HelperMacros.h>using namespace CPPUNIT_NS;class someTest : public TestFixture {  CPPUNIT_TEST_SUITE(someTest);   CPPUNIT_TEST(test1);
    CPPUNIT_TEST(test2);    CPPUNIT_TEST_SUITE_END();   void test1(){       CPPUNIT_ASSERT( some(true) == false );
    }

    void test2(){
        CPPUNIT_ASSERT( some(false) == true );
    }};CPPUNIT_TEST_SUITE_REGISTRATION(reverseTest);

someがbool値を入れ替えるかどうかのテスト
ソースファイルをインクルードしているけれど、他人に見せるようなものでないならこの方がコンパイルが楽。

some.cc
bool some(bool tf){
    return !tf;
}

これで完了。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?