#include "CppUTest/TestHarness.h"
#include "CppUTestExt/MockSupport.h"
TEST_GROUP(MockFail)
{
virtual void setup()
{
}
virtual void teardown()
{
mock().checkExpectations();
mock().clear();
}
};
TEST(MockFail, veryLongTimeToEnd)
{
mock().expectNCalls(30000, "MainDelay");
}
float get()
{
return mock().actualCall("ivexpget").returnValue().getDoubleValue();
}
#include "CppUTest/TestHarness.h"
#include "CppUTestExt/MockSupport.h"
void MainDelay()
{
mock().actualCall("MainDelay");
}
TEST_GROUP(MockFail)
{
virtual void setup()
{
}
virtual void teardown()
{
mock().checkExpectations();
mock().clear();
}
};
TEST(MockFail, veryLongTimeToEnd)
{
const int n = 500;
mock().expectNCalls(n, "MainDelay");
for (int i = 0; i < n; ++i) MainDelay();
}
--
On 28 Oct 2014, at 22:56, Vitaliy Bortsov wrote:
I attach a part of my working project.
I want to discuss with TDD followers for some problems regarding that
project.
1. File organization.
That archive has two eclipse projects: for target and for PC (cygwin,
gcc, in directory tests).
Test project use production code and test code.
Production code use RTOS (FreeRTOS) and for now consist of some base blocks
irrelevant to RTOS. There are tests for those base blocks.
But when I go writing tests for RTOS tasks then it is too uncomfortably
to use production code, it is better to use mock instead of production code
(break dependency).
Testing your RTOS independent of you product seems like a good idea. Are these contract tests, tests that tell you if the RTOS works as expected.
For one test project, it is impossible (one executable
cannot use production code and mock functions with the same name).
If you are doing link-time substitution, a suitable choice for swapping out the real RTOS, then you only get one global instance of any symbol.
Do I
need to create many test projects (one test project for one task) instead
of one test project? What is best approach?
You can just have different makefiles or make targets.
2. Problems with big number call of mock()
File tests/testsrc/MeasureRValveExp_test.cpp has
IGNORE_TEST(MeasureRValveExp, shortCircuit) which is hangs up PC.
If you are referring to the expectNCalls(30000, ...), for starters, don't use a mock. Use a hand crafted fake that counts the calls. Does something special happen on call 30001. Your own fake will eliminate the test execution time problem.
As Ryan
said, there are an issue with that test. Can you help me to detect an issue?
I think Ryan and I were suggesting that you should not need 30,000 loops and calls in a unit test. What are you testing? Is the code in your zip file?
It is more likely a problem with the structure of your code that leads to an inconvenient test.
James
Best regards,
Vitaliy Bortsov
--
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/d/optout.
[project.zip]