in my tests, I sometimes face the error that the tests run too long: "Watchdog Tripped Error - Code Executed Too Long".
Actually, I believe that the production code I am testing is "more or less and in most cases" :p fine from a performance point of view. The failure mainly happens because I kind of parameterize my tests, i. e. within a test method, I define a large array or dictionary with test data and I call my method under test in a loop.
Example:
(:test)
static function testTrim(logger)
{
var testDataArray = [
{ :input => "bla", :expected => "bla"},
{ :input => "bl a", :expected => "bl a"},
{ :input => " bla", :expected => "bla"}
];
for (var i=0; i<testDataArray.size(); i++)
{
var testData = testDataArray;
var trimmedString = FhemStringUtils.trim(testData[:input]);
Test.assertEqual(trimmedString, testData[:expected]);
}
return true;
}
[/CODE]
(btw: This code does not cause the error, it is just an example. It usually happens in more complex scenarios)
Does anyone here have a solution? Maybe another pattern how I can write such tests? Or some way to disable/increase the threshold for tests?
Thanks & best regards,
Florian