Come posso scrivere un'asserzione personalizzata, come assertFoo($expected, $actual)
, che si comporta come le asserzioni predefinite rispetto all'errore "stack trace"?Come scrivere asserzione PHPUnit personalizzata che si comporta come un'asserzione incorporata?
ho attualmente il seguente metodo definito (all'interno di una classe che estende PHPUnit_Framework_TestCase
):
public static function assertFoo($expected, $actual) {
self::assertEquals($expected, $actual);
}
Se chiamo questo da un test e il test fallisce, ottengo due elementi nello stack di chiamata:
1) PreferencesTest::testSignupTeacher
Failed asserting that 5 matches expected 3.
/vagrant/myproject/tests/integration/PreferencesTest.php:17
/vagrant/myproject/tests/integration/PreferencesTest.php:136
La riga 17 è dove assertFoo()
chiama il numero assertEquals()
integrato e ha esito negativo; linea 136 è lì assertFoo()
è chiamato.
Se cambio il test di chiamare assertEquals()
direttamente, ho solo uno:
1) PreferencesTest::testSignupTeacher
Failed asserting that 3 is true.
/vagrant/myproject/tests/integration/PreferencesTest.php:136
C'è un po 'documentation in the manual, ma non sembra per coprire questo.
Puoi mostrare il codice per la tua funzione assertFoo(). –
@DarrenCook Certo, aggiornato. – mjs