Cpputest, Eclipse CDT - MOCKS

783 views
Skip to first unread message

CW

unread,
Jun 18, 2013, 10:56:56 AM6/18/13
to cppu...@googlegroups.com
I have started to get to grips with Eclipse CDT and CppUTest.

I can run simple tests OK, but usage of mock cause build errors.

What have I done wrong? I setup eclipse as per this guide schuchert.wikispaces.com,
MinGw and msys (latest)
CppUTest v3.3
Eclipse Library : "<path>\CPPUTEST\lib."
Eclipse Include "<path>\CPPUTEST\include"

Actual Error:

\Debug/../Tests/mocks.cpp:33: undefined reference to `mock(SimpleString const&)'

Code:

#include <CppUTest/TestHarness.h>
#include <CppUTestExt/MockSupport.h>
using namespace std;

TEST_GROUP(MockDocumentation)
{
    void teardown()
    {
        mock().clear();
    }
};

void productionCode()
{
    mock().actualCall("productionCode");
}

TEST(MockDocumentation, SimpleScenario)
{
    mock().expectOneCall("productionCode");
    productionCode();
    mock().checkExpectations();
}

A. Robert S.

unread,
Jun 18, 2013, 12:39:29 PM6/18/13
to cppu...@googlegroups.com
I'm not into eclipse, and this is just on a hunch - did you link libCppUTestExt.a as well?
R.

Bas Vodde

unread,
Jun 18, 2013, 9:58:16 PM6/18/13
to cppu...@googlegroups.com

I'd guess the same thing. You are missing a library to link to…

Bas
> --
> You received this message because you are subscribed to the Google Groups "cpputest" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

CW

unread,
Jun 19, 2013, 4:33:15 AM6/19/13
to cppu...@googlegroups.com
Thanks for the pointers you were right I had forgotten to add the CppUTestExt Library. All working now!

So in summary, follow linked guide instructions, however on page 11 for section "Library Path & Included Libraries"

Project Properties -> Settings -> MinGW Linker
Add "<path>CPPUTEST\Lib" to library search path -L
Add "CppUTest" to the Libraries -l
Add "CppUTestExt" to the Libraries -l

A. Robert S.

unread,
Jun 19, 2013, 12:24:03 PM6/19/13
to cppu...@googlegroups.com
Thanks for the links above. That book is one of a kind (introduction to C++, OOD and TDD all in one).
However, as you discovered, using mocks does not seem to be in its scope.
 
If you are programming in C++ -- and that is a big IF -- you may want to have a closer look at the methods used in the book, as they support good object-oriented design and are a good alternative to using CppUTest mocks.
 
Robert
Reply all
Reply to author
Forward
0 new messages