1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【PHPUnit】PHPUnit上でメソッド単位のテスト実行をしたいので調べた

Posted at

やりたいこと

unitTest.php
public function testA ()
{
    // テストAの処理
}

public function testB ()
{
    // テストBの処理
}

このようなコードで、testAを実行せずにtestBだけ実行したい場面があると思います。
自分は今までtestAをコメントアウトしてました

解決方法

メソッド単位で実行できないのかなー...と思って調べたところ、同じ悩みを発見。
https://qastack.jp/programming/26095051/how-to-run-single-test-method-with-phpunit

$ phpunit --filter testB unitTest.php

こうすればtestBだけ実行できます。


調べていくうちに @group を設定したほうがよりPHPUnitらしいなと思いました。

unitTest.php
/**
 * @group one
 */
public function testOne ()
{
    // テストAの処理
}

/**
 * @group two
 */
public function testTwo ()
{
    // テストBの処理
}

各テストに@groupアノテーションを付けます。

testOne()だけ実行したいときは

$ phpunit --group one

解決。

お読みいただきありがとうございました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?