Home » Community » U++ community news and announcements » ide: Compare with log and new 'unit' testing method
ide: Compare with log and new 'unit' testing method [message #54601] |
Wed, 19 August 2020 10:59  |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
So I have got an idea how to simplify unit testing, or at least what I consider unittesting in U++ context...
Traditionally, checks in unit testing are something similar to a tedious list of ASSERTs. So far, in many tests, this is exactly what I was doing in autotest too.
Recently I have introduced a new approach: Instead of individual ASSERTs, test normally LOGs values out, creating standard U++ log. Then, at the end of test, this log is compared with "Etanol.log" in the test package.
When creating the test, you simply output all values of interest, like
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
{ Vector<int> x(20); DUMP(x.GetCount()); }
{ Vector<int> x(20, 123); DUMP(x); }
{ Vector<String> x(20, "123"); DUMP(x); }
{ Array<int> x(20); DUMP(x.GetCount()); }
{ Array<int> x(20, 123); DUMP(x); }
{ Array<String> x(20, "123"); DUMP(x); }
}
You check that the output is correct, then create the file "Etalon.log", copy current log into it and add CheckLogEtalon(); call at the end of MAIN.
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
{ Vector<int> x(20); DUMP(x.GetCount()); }
{ Vector<int> x(20, 123); DUMP(x); }
{ Vector<String> x(20, "123"); DUMP(x); }
{ Array<int> x(20); DUMP(x.GetCount()); }
{ Array<int> x(20, 123); DUMP(x); }
{ Array<String> x(20, "123"); DUMP(x); }
CheckLogEtalon();
}
CheckLogEtalon loads current log, etalon log, fixes them a bit (removes first line which is in principle different, removes '\r' to avoid problems) and compares. If they are equal, test passes. (CheckLogEtalon is now in Core/Diag.h).
To support this, I have also added "Compare with log" function to the ide - if the test fails, you can use that to quickly find the culprit.
|
|
|
|
Goto Forum:
Current Time: Sun May 11 15:35:16 CEST 2025
Total time taken to generate the page: 0.03107 seconds
|