1
0
Fork 0
mirror of https://github.com/pnx/neotest-phpunit synced 2026-06-16 03:54:55 +02:00

Add test for failures

This commit is contained in:
Michael Utz 2022-11-16 22:34:14 +03:00
parent f2e87a2f99
commit a2045b85bc

View file

@ -216,4 +216,131 @@ describe("get_test_results", function()
assert.are.same(utils.get_test_results(xml_output, output_file), expected) assert.are.same(utils.get_test_results(xml_output, output_file), expected)
end) end)
it('parses output with a failing test', function()
local xml_output = {
testsuites = {
testsuite = {
_attr = {
assertions = "16",
errors = "0",
failures = "1",
name = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
skipped = "0",
tests = "6",
time = "0.007869",
warnings = "0"
},
testsuite = {
_attr = {
assertions = "16",
errors = "0",
failures = "1",
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
name = "P\\Tests\\Feature\\UserTest",
skipped = "0",
tests = "6",
time = "0.007869",
warnings = "0"
},
testcase = { {
_attr = {
assertions = "3",
class = "Tests\\Feature\\UserTest",
classname = "Tests.Feature.UserTest",
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
name = "class constructor",
time = "0.003293"
}
}, {
_attr = {
assertions = "2",
class = "Tests\\Feature\\UserTest",
classname = "Tests.Feature.UserTest",
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
name = "tellName",
time = "0.000584"
}
}, {
_attr = {
assertions = "2",
class = "Tests\\Feature\\UserTest",
classname = "Tests.Feature.UserTest",
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
name = "can tellAge",
time = "0.000396"
}
}, {
_attr = {
assertions = "1",
class = "Tests\\Feature\\UserTest",
classname = "Tests.Feature.UserTest",
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
name = "is false",
time = "0.001134"
},
failure = { "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::it is false\nFailed asserting that true is false.\n\n/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php:33\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Expectation.php:316\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/Reflection.php:38\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/HigherOrderMessage.php:96\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/HigherOrderMessageCollection.php:43\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Factories/TestCaseFactory.php:148\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Concerns/Testable.php:302\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Support/ExceptionTrace.php:29\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Concerns/Testable.php:303\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Concerns/Testable.php:279\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/src/Console/Command.php:119\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/bin/pest:62\n/Users/michaelutz/Code/neotest-pest/vendor/pestphp/pest/bin/pest:63",
_attr = {
type = "PHPUnit\\Framework\\ExpectationFailedException"
}
}
}, {
_attr = {
assertions = "3",
class = "Tests\\Feature\\UserTest",
classname = "Tests.Feature.UserTest",
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
name = "addFavoriteMovie",
time = "0.001189"
}
}, {
_attr = {
assertions = "5",
class = "Tests\\Feature\\UserTest",
classname = "Tests.Feature.UserTest",
file = "/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php",
name = "removeFavoriteMovie",
time = "0.001273"
}
} }
}
}
}
}
local expected = {
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::addFavoriteMovie"] = {
output_file = output_file,
short = "TESTS.FEATURE.USERTEST\n-> PASSED - addFavoriteMovie",
status = "passed"
},
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::can tellAge"] = {
output_file = output_file,
short = "TESTS.FEATURE.USERTEST\n-> PASSED - can tellAge",
status = "passed"
},
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::class constructor"] = {
output_file = output_file,
short = "TESTS.FEATURE.USERTEST\n-> PASSED - class constructor",
status = "passed"
},
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::is false"] = {
errors = { {} },
output_file = output_file,
status = "failed"
},
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::removeFavoriteMovie"] = {
output_file = output_file,
short = "TESTS.FEATURE.USERTEST\n-> PASSED - removeFavoriteMovie",
status = "passed"
},
["/Users/michaelutz/Code/neotest-pest/tests/Feature/UserTest.php::tellName"] = {
output_file = output_file,
short = "TESTS.FEATURE.USERTEST\n-> PASSED - tellName",
status = "passed"
}
}
assert.are.same(utils.get_test_results(xml_output, output_file), expected)
end)
end) end)