How do I dump variables to the screen when running PHPUnit tests? I'm trying to put together some PHPUnit tests in Drupal 8. I'm running the tests from the command line, using /vendor/bin/phpunit, but I'm having troubles figuring out how to dump a variable to the screen for debugging purposes.

For that matter, I'm using this:

$this-&gt;assertEquals(2, $this-&gt;currentUser-&gt;id(), 'ID is correct');


And when it passes, the message 'ID is correct' is not shown in the console. Does anyone know how to make the error messages properly show?
Recent versions of PHPUnit swallow output.  To get around this, you need to run with the --debug flag, eg

$ ../vendor/bin/phpunit --debug modules/migrate/tests/src/Unit/process/FormatDateTest.php


Then you can see printed output.

Also note that PHPUnit will skip tests with output in them with the default phpunit.xml file, because it will deem them risky.   To avoid this update the beStrictAboutOutputDuringTests="false" setting and your tests will run.

You can also use the $message parameter to output something when an assertion fails.