This example shows how to use WebListener to report the results and monitor the tests from a web browser.
#include <cstdio>
#include <cstdlib>
#include <ctime>
#ifdef _WIN32
# include <Windows.h>
#else
# include <unistd.h>
#endif
class MyTest1 : public TestCase
{
public:
MyTest1() :
TestCase("MyTest1")
{
}
void run() override
{
srand(time(nullptr));
for (int i = 0; i < 10; i++) {
int a = rand() % 10;
int b = rand() % 10;
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
}
}
};
class MyTest2 : public TestCase
{
public:
MyTest2() :
TestCase("MyTest2")
{
}
void run() override
{
srand(time(nullptr));
for (int i = 0; i < 10; i++) {
int a = rand() % 10;
int b = rand() % 10;
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
}
}
};
int main(int argc, char** argv)
{
WebProgressListener web(8080, false);
TestResultCollector collector;
TestResult result;
result.addListener(&web);
result.addListener(&collector);
printf("To see the test result, open a web browser and type 'http://127.0.0.1:8080'...\n");
TestSuite suite("MyTestSuite");
MyTest1 test1;
MyTest2 test2;
suite.addTest(&test1);
suite.addTest(&test2);
TestRunner runner;
runner.addTest(&suite);
runner.run(result);
return collector.failedCount();
}
#define ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(condition, message)
Conditional failure report.
#define ROBOTTESTINGFRAMEWORK_TEST_REPORT(message)
Reporting a message to the TestResult.