PHPUnit validation function outside the class

I am very new to PHPUnit and unit testing, so I have a quest: Can I test a function outside the class, for example:

function odd_or_even( $num ) { return $num%2; // Returns 0 for odd and 1 for even } class test extends PHPUnit_Framework_TestCase { public function odd_or_even_to_true() { $this->assetTrue( odd_or_even( 4 ) == true ); } } 

Now it just returns:

 No tests found in class "test". 
+7
source share
1 answer

In order for them to be recognized as a test, you need to assign the names of your functions to "test".

From the documentation:

  1. Tests are public methods called test *.

Alternatively, you can use the @test annotation in the docblock method to mark it as a testing method.

There should be no problem calling odd_or_even() .

For example:

 class test extends PHPUnit_Framework_TestCase { public function test_odd_or_even_to_true() { $this->assertTrue( odd_or_even( 4 ) == true ); } } 
+11
source

All Articles