La respuesta dada por @stijn tiene un error en la manipulación de la lista de prueba y, por lo tanto, generalmente ejecuta pruebas adicionales que no solicitó.
Este ejemplo utiliza un funcionador de predicados y también aprovecha la coincidencia de nombres de conjunto de aplicaciones integrada proporcionada por RunTestsIf. Es correcto y mucho más simple.
#include "UnitTest++.h"
#include "TestReporterStdout.h"
#include <string.h>
using namespace UnitTest;
/// Predicate that is true for tests with matching name,
/// or all tests if no names were given.
class Predicate
{
public:
Predicate(const char **tests, int nTests)
: _tests(tests),
_nTests(nTests)
{
}
bool operator()(Test *test) const
{
bool match = (_nTests == 0);
for (int i = 0; !match && i < _nTests; ++i) {
if (!strcmp(test->m_details.testName, _tests[i])) {
match = true;
}
}
return match;
}
private:
const char **_tests;
int _nTests;
};
int main(int argc, const char** argv)
{
const char *suiteName = 0;
int arg = 1;
// Optional "suite" arg must be followed by a suite name.
if (argc >=3 && strcmp("suite", argv[arg]) == 0) {
suiteName = argv[++arg];
++arg;
}
// Construct predicate that matches any tests given on command line.
Predicate pred(argv + arg, argc - arg);
// Run tests that match any given suite and tests.
TestReporterStdout reporter;
TestRunner runner(reporter);
return runner.RunTestsIf(Test::GetTestList(), suiteName, pred, 0);
}
Es necesario que nos dirá más acerca de su entorno, lo que ha intentado y ha fallado, etc. –
Así que ya sabe cómo ejecutar dos pruebas ¿entonces? –
Estoy ejecutando UnitTest ++ fuera de la caja como está.Mi función principal se ve así: int main() { \t \t printf ("prueba de diamante v0.1% s \ n \ n", __ TIMESTAMP__); \t diamond :: startup(); \t \t UnitTest :: RunAllTests(); \t \t diamond :: shutdown(); \t \t printf ("presione cualquier tecla para continuar ..."); \t getc (stdin); \t \t } para la depuración Me gustaría escribir algo así como \t unittest :: RunSingleTests ("MyNewUnitTest"); en lugar de \t UnitTest :: RunAllTests(); . Quería saber si existe tal tipo de función y, en caso afirmativo, cómo se ve la sintaxis. – Arno