Esiste un modo più ufficiale per forzare un errore di phpunit rispetto a $this->assertTrue(false)
?Come forzare un errore con phpunit
40
A
risposta
69
Credo che questo dovrebbe funzionare all'interno di un banco di prova:
$this->fail('Message');
1
Sì, c'è un modo,
$this->fail("your message");
se si desidera visualizzare la pagina u hanno fallito di
print_r(getResponse()->getContent());
+0
' getResponse() 'è una funzione specifica del framework, che potrebbe non essere generalmente disponibile. – bishop
1
Un altro modo per farlo (particolarmente utile quando si scrive uno strumento di test) è:
use PHPUnit_Framework_ExpectationFailedException as PHPUnitException;
try {
// something here
} catch (SpecificException $e) {
// force a fail:
throw new PHPUnitException("This was not expected.");
}
Problemi correlati
- 1. Errore con PHPUnit in Symfony2
- 2. Errore phpStorm PHPUnit testreporter
- 3. Errore PHPUnit "indice indefinito: HTTP_HOST"
- 4. errore durante l'esecuzione di PHPUnit
- 5. Come installo correttamente PHPUnit con PEAR?
- 6. Test phpunit con database
- 7. Come posso forzare un errore di compilazione in C++?
- 8. test error_log con PHPUnit
- 9. Errore Netbeans-PHPUnit "Nessun test eseguito"
- 10. come sostituire i metodi con phpunit
- 11. Come aggregare PHPUnit con il mio codice?
- 12. verifica il valore di ritorno di un metodo che attiva un errore con PHPUnit
- 13. Come confrontare XML simili con PHPUnit?
- 14. Come forzare Camelcase con JavaScriptSerializer?
- 15. selezionare un'opzione con selenium2 + phpunit
- 16. mb_convert_encoding() non funziona con phpunit
- 17. Zend Framework 2 phpunit testare una tabella con un join
- 18. PhpStorm con PHPUnit: PHP_CodeCoverage_Filter non trovato
- 19. come testare mail() utilizzando PHPUnit
- 20. Perché phpunit non mostra alcun errore nella console
- 21. Come forzare l'installazione di un pacchetto?
- 22. Come catturare PHP Warning in PHPUnit
- 23. Configurazione di PHPUnit con Gitlab Integrazione continua
- 24. PHPUnit: Fatal movimentazione
- 25. Come posso forzare l'accesso con l'API OAuth?
- 26. Come installare la vecchia versione di PHPUNIT?
- 27. PHPUnit - verifica controller MVC con variabile $ _POST
- 28. Netbeans: come configurare il percorso PHPUnit di un server remoto?
- 29. PHPUnit StackTest :: assertEmpty() deprecato
- 30. Test della funzione mt_rand con PHPUnit
Il $ this-> fail() interromperà l'esecuzione del test, quindi questo non dovrebbe essere usato in sostituzione delle asserzioni per visualizzare un messaggio se nel test sono presenti più asserzioni. – Prusprus
Passare un'eccezione a 'fail' comporterà una bella stacktrace –