2

ここの回答で説明されているメイクファイルがあります。

CPPUTestMakeFile ヘルプのリンク

私は私のcppファイルに持っています:

#include "CppUTest/CommandLineTestRunner.h"

int main(int ac, const char** av)
{
/* These checks are here to make sure assertions outside test runs don't crash */
CHECK(true);
LONGS_EQUAL(1, 1);

return CommandLineTestRunner::RunAllTests(ac, av);
}

次に、エラーが発生します。

undefined reference to `CommandLineTestRunner::RunAllTests(int, char const**)'

何を試してみますか?

4

3 に答える 3

0

コードを AllTest.ccp メイン ファイルの 1 つにコピーしたところ、問題なく動作しました。

RunAllTests() の 2 番目の形式のみを定義する古いバージョンの CppUTest を使用している可能性があります。

static int RunAllTests(int ac, const char** av);
static int RunAllTests(int ac, char** av);

私は通常、RUN_ALL_TESTS マクロを使用し、次のように argc を const char * として定義します。

#include "CppUTest/CommandLineTestRunner.h"

int main(int ac, const char** av)
{
    return RUN_ALL_TESTS(ac, av);
}
于 2014-05-15T16:56:29.700 に答える
0

cpputest ケースを実行するには、2 つのファイルが必要です。1 つはすべてのテスト ケースを含み、もう 1 つはmain()関数のみを含む必要があります。

このようなことを試してみてください -

ファイル: cpptest1.cpp

#include "CppUTest/TestHarness.h"
TEST_GROUP(FirstTestGroup)
{
};

TEST(FirstTestGroup, FirstTest)
{
   FAIL("Fail me!");
}
TEST(FirstTestGroup, SecondTest)
{
   STRCMP_EQUAL("hello", "world");
   LONGS_EQUAL(1, 2);
   CHECK(false);
}

ファイル: cpptestmain.cpp

#include "CppUTest/CommandLineTestRunner.h"
int main(int ac, char** av)
{
   return CommandLineTestRunner::RunAllTests(ac, av);
}

testsこれら 2 つのファイルが、cpputest ディレクトリの同じフォルダー ( ) にあることを確認してください。そして、make ファイルでこれらのフォルダーをリンクします。詳細については、このサイトをご覧ください

于 2014-08-13T05:58:58.697 に答える