Marking a function as a test in PHPUnit

I don't like the policy of prepending a method name in order to make it testable. For instance, suppose I am testing the method getName(). My test might look like this:

  public function testGetName()
  {
      ...
  }

By adding 'test' at the front of the method, I have obfuscated the method, and it takes a little bit longer to know what I am testing.

That's why I like to use annotations instead:

  /**
   * @test
   */
  public function getName()
  {
     ....
  }

If you add the annotation @test to your doc block before the function, PHPUnit will recognize it, and execute the method as a unit test.


No comments:

Post a Comment