yts*_*jam 43 php phpunit laravel
我正在尝试学习如何使用phpunit和laravel进行测试.使用phpunit命令启动测试时,我收到警告:
There was 1 failure:
1) Warning
No tests found in class "PostsTest".
FAILURES!
Tests: 2, Assertions: 1, Failures:
Run Code Online (Sandbox Code Playgroud)
我的测试类名和文件名匹配.我已经阅读了有关不匹配名称的其他问题.我的文件名是PostsTest.php和我的测试文件:
class PostsTest extends ApiTester {
public function it_fetches_posts()
{
$this->times(5)->makePost();
$this->getJson('api/v1/posts');
$this->assertResponseOk();
}
private function makePost($postFields=[])
{
$post = array_merge([
'title' => $this->fake->sentence,
'content' => $this->fake->paragragraph
], $postFields);
while($this->times --)Post::create($post);
}
}
Run Code Online (Sandbox Code Playgroud)
如果有必要,我的ApiTester:
use Faker\Factory as Faker;
class ApiTester extends TestCase {
protected $fake;
protected $times = 1;
function __construct($faker)
{
$this->fake = Faker::create();
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道错误在哪里.Laravel或我当地的phpunit设置或其他任何东西.任何帮助表示赞赏.
谢谢.
CJ *_*son 83
/** @test */
public function it_tests_something()
{
...
}
Run Code Online (Sandbox Code Playgroud)
添加它@test告诉phpunit将该函数视为测试,无论名称如何.