Laravel 单元测试 - 运行所有测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17936568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Unit Testing - Run All Tests
提问by MuffinTheMan
I'm pretty new to both Laravel and PHPUnit, and I'm using Laravel 4 on Ubuntu 12.04.
我对 Laravel 和 PHPUnit 都很陌生,我在 Ubuntu 12.04 上使用 Laravel 4。
When I run phpunit
from my project's home directory, it runs the ExampleTest.php test that comes with Laravel. I created my own sample test (exactly like their example and in the same directory, only the file and test are renamed and do something different), and ran phpunit
again like before; but it still only ran ExampleTest.php--not my created test. But if I run phpunit path/to/myTest
, it runs my test just fine. So I feel like this is a dumb question, but how do I run all of the tests with one command (I thought phpunit
should've done that)?
当我phpunit
从项目的主目录运行时,它会运行 Laravel 附带的 ExampleTest.php 测试。我创建了自己的示例测试(与他们的示例完全一样,并且在同一目录中,只有文件和测试被重命名并执行不同的操作),然后phpunit
像以前一样再次运行;但它仍然只运行 ExampleTest.php——不是我创建的测试。但是如果我运行phpunit path/to/myTest
,它运行我的测试就好了。所以我觉得这是一个愚蠢的问题,但是我如何使用一个命令运行所有测试(我认为phpunit
应该这样做)?
Thanks for the help!
谢谢您的帮助!
回答by Laurence
Your tests need to finish with ...Test.php to run automatically. So change
您的测试需要以 ...Test.php 完成才能自动运行。所以改变
app/tests/TestCreateEvent.php
to
到
app/tests/CreateEventTest.php
and it should work.
它应该工作。
Also make sure you rename the model inside the test to "class CreateEventTest extends TestCase"
还要确保将测试中的模型重命名为"class CreateEventTest extends TestCase"