Coming back after illness. What is biggest pain? I do not remember what I was doing. No principles. No details.
I read on my blog that test method should not return value. Seems easy?
In file mwtest/PtrTestMethod.h, I replace the returned value
typedef void(TestCase::*PtrTestMethod)(void);
What should happen?
The entire program should not compile. And so it is.... read more
Each test method returns a integer value: 0 means success, 1 means failure.
trivial
return 0;
no-trivial simulates assertTrue()
return !(c == 4);
but only once per class
The tests should have many asserts.
There is no sense in returning the value.
So the signature of the test method can be changed, so it returns void
But the result of test method must be evaluated.
Vector of AssertInfo will be used.... read more
Revision [r22]
TestCase/
{...}Test.h - test classes
example.cpp - running test classes
doc/
mwtest/
PtrTestMethod.h - pointer to the test method of TestCase class
TestMethodResult.h - enum with possible results of the test method
AssertInfo.h - structure with the name and result of the assert
MethodContainer.h - structure contains pointer to the method and also its result
Assertions.h - base class defines assertions and pointer to current MethodContainer
TestCase.h - base class for tests... read more
The test is a class. Classes have members. So the test class can contain its name.
The test method is a function. There is problem in storing its name internally.
Revision [r15]
I decide to store function name outside function.
There is a struct named MethodContainer that contains method pointer and its properties.
~~~~~~~~~~~~
class NoAssertTestFuncNameTestCase;
typedef int(NoAssertTestFuncNameTestCase::*PtrTestMethod)(void);... read more
Setting the name is moved to the base class which is the class that declares thet member
I move setting the name property of the test class to the base class
~~~~~~~~~~~~~~~~~~
using namespace std;
class NoAssertTestNameTestCase;
typedef int(NoAssertTestNameTestCase::*PtrTestMethod)(void);
class NoAssertTestNameTestCase {
protected:
int nTests;
int nFails;
vector<ptrtestmethod> tests;
string name; ... read more</ptrtestmethod>
I want to identify the test class by its name.
I want to display the name of the class in the runTests() methods.
In future the test name will be displayed in the result summary.
Test creator has two possibilities:
What happens in the second situation?
Constructor sets the class name as the name property.
How to achieve it without reflection?
The __func__contains the name of the current function.
ACTION. The name of the constructor is the same as the class name.
What is the problem?
I must use the name of derived class, not from the derived class.... read more
Still revision [r10]
Code is similar to previous one.
~~~~~~~~
using namespace std;
class NoAssertTestCase;
typedef int(NoAssertTestCase::*PtrTestMethod)(void);
class NoAssertTestCase {
protected:
int nTests;
int nFails;
vector<ptrtestmethod> tests; </ptrtestmethod>
public:
NoAssertTestCase() : nTests(0), nFails(0) { }
void appendTestMethod(PtrTestMethod ptm) {
tests.push_back(ptm);
nTests++;
}
void runTests() {
vector<ptrtestmethod>::const_iterator it;
for(it = tests.begin(); it != tests.end(); ++it) {
int testResult = (this->**it)();
if(testResult) {
nFails++;
}
}
}</ptrtestmethod>
void displayResults() {
cout << nFails << "/" << nTests << " fails" << endl;
}
};
~~~~~~~~... read more
SimpleTestCase.h according to [r10] commit.
Below is the class without specific test.
This "framework" should be moved to base class.
~~~~~~~~~~
using namespace std;
// forward declaration allows defining PtrTestMethod
class SimpleTestCase;
/** Pointer to a test method which is a member of SimpleTestCase
Starting svn/sf not sure about importing, commiting, checking out.
I'm creating manually subfolders: trunk, branches, tags.
The general idea: test runner should be in headers.
So I use only inline functions.
No inheritance.