PHPUnit has two special annotations to indicate a test should run in a background process: a class annotation @runTestsInSeparateProcesses
that affects all tests in the current class, and a test annotation @runInSeparateProcess
that affects the current test.
This is useful in some cases when the tested class needs to print some output, so it would not mess up with PHPUnit's own output.
So, here's my question: is the TestCase class aware of this fact? Does it know when it's running on background? If so, is there a method to detect it?
I'm looking for something like $this->isRunningOnBackground()
.
I did not find anything about this in the documentation.
Browsing PHPUnit's source code, I found a boolean protected property in TestCase class $runTestInSeparateProcess
that is set to true when the annotation is present. There's a $runClassInSeparateProcess
as well, but it's set to private, so you won't access it in a child class context.
We can detect if a test is running on background by just checking if ($this->runTestInSeparateProcess) {...}
inside setUp() or tearDown().
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.