small medium large xlarge

Generic-user-small
04 Jan 2017, 08:20
sam dup (3 posts)

On page 62 the book asks us to make a test called OutOfBoundsProducesRuntimeError.

I made it and then, like it was supposed to, it failed. Right after the book says that the test should fail the book says “Now add the call to RUNTIME_ERROR(); the test passes.”

I have no idea what add the call to RUNTIME_ERROR(): means. I looked at the correct code in your bookcode and it looks just like mine but mine draws a failure.

here is my test

TEST(LedDriver, OutOfBoundsProducesRunTimeError)
{
    LedDriver_TurnOn(-1);
    TEST_ASSERT_EQUAL_STRING("LED Driver: out-of-bounds LED", RuntimeErrorStub_GetLastError());
    TEST_ASSERT_EQUAL(-1, RuntimeErrorStub_GetLastError());
}

this is exactly what the one in the book looks like. When i run make I get the error that Expected ‘LED Driver: out-of-bounds LED’ Was ‘No Error’

I tried to add the line RUNTIME_ERROR(“LED Driver: out-of-bounds LED”,-1); to the test but then I got the error Expected -1 Was 4223633

which was really weird. Any help?

Generic-user-small
04 Apr 2017, 03:03
Guillermo (1 post)

Hi, i think you should add the RUNTIME_ERROR() in the test case like this:

TEST(LedDriver,OutOfBoundsProducesRuntimeError) { LedDriver_TurnOn(-1); RUNTIME_ERROR(“LED Driver: out-of-bounds LED”,-1); TEST_ASSERT_EQUAL_STRING(“LED Driver: out-of-bounds LED”, RuntimeErrorStub_GetLastError()); TEST_ASSERT_EQUAL(-1,RuntimeErrorStub_GetLastParameter()); }

i was struggling with that too, the book is not very clear in that part

James2009_pragsmall
05 Apr 2017, 11:51
James Grenning (161 posts)

Hi

The idea was to create a test stub version of a function or macro called RUNTIME_ERROR that takes two parameters. Your test stub version would hold on to the parameters so that the test case can check them.

Does that help?

James

You must be logged in to comment