Laravel 能否在设置中排除一种测试方法?(拉威尔测试实验室)
我正在寻找一种优雅的方法来排除phpunit设置的一种测试方法。 要进一步解释,请参见以下代码:Laravel 能否在设置中排除一种测试方法?(拉威尔测试实验室),laravel,phpunit,Laravel,Phpunit,我正在寻找一种优雅的方法来排除phpunit设置的一种测试方法。 要进一步解释,请参见以下代码: public function setUp() { parent::setUp(); $this->signUp; //creates and logs in the user } /** @test */ public function guest_cannot_see_request_page() { $this->get(route('requests
public function setUp()
{
parent::setUp();
$this->signUp; //creates and logs in the user
}
/** @test */
public function guest_cannot_see_request_page()
{
$this->get(route('requests.list'))
->assertRedirect(route('login'));
}
但是我想排除guest\u cannot\u see\u request\u page()方法的登录。因为它应该是客人。对于我的所有其他方法,用户已登录。您的测试方法将根据以下标准执行:
- 它有一个
docblock参数@test
- 方法名称以
test
/** @test */
public function guest_cannot_see_request_page()
{
$this->get(route('requests.list'))
->assertRedirect(route('login'));
}
或
如果要禁用为测试调用的方法,只需确保未应用以下两种方法中的任何一种:
/** Just human readable */
public function guest_cannot_see_request_page()
{
// This test will not be executed
$this->get(route('requests.list'))
->assertRedirect(route('login'));
}
注意请注意,phpunit会将此视为跳过测试的风险。如果将setUp()方法重命名为manualSetUp(),并在要运行代码的测试方法开始时调用它,则可以获得所需的结果。将该测试放在另一个文件中。可能只包含单个测试无法排除未处理的“设置”。@matiaslauriti好的,我记得我在Laracast上看了一段视频,您可以忽略一个测试方法。不记得我在哪里见过它,不过还是谢谢你!您可以跳过测试,但这意味着它不会在其中运行任何内容。请参阅。这根本没有回答问题-OP确实希望为来宾运行测试,但在这种情况下,阻止首先运行安装方法中的代码。
/** Just human readable */
public function guest_cannot_see_request_page()
{
// This test will not be executed
$this->get(route('requests.list'))
->assertRedirect(route('login'));
}