Skip to content

Instantly share code, notes, and snippets.

@IceTimux

IceTimux/aia5k.md

Last active Nov 25, 2020
Embed
What would you like to do?

~PHPUnit | assertTrue() vs. assertEquals()


When using assertTrue() with some condition, the error message is often not useful. In this case it is better to use assertEquals() or similair that produces more meaningful output.

Consider the following example.

// if this test fails...
$this->assertTrue($users->count() == 1);
// You get the following mesage: "Failed asserting that false is true"

// Which doesn't give much information on what happened and where

// if this test fails...
$this->assertEquals(1, $user->count());
// You get the following message: "Failed asserting that 4 matches expected 1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment