On JUnit, you can use the annotation @RunWith(Parameterized.class) to run a single unit test several times with different actual and expected results. I'm new to PHPUnit so I would like to know which are suggested approachs for achieving the same (running one unit test with many actual, expected results)?
PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit design for unit testing systems that began with SUnit and became popular with JUnit. Even a small software development project usually takes hours of hard work.
Test parameterization is a type of data-driven testing that allows you to execute the same test, multiple times using different parameters. Xray Cloud has a parameterized tests feature, that executes the same test with different input values, multiple times, without ever having to clone or replicate it.
The assertEquals() function is a builtin function in PHPUnit and is used to assert whether the actual obtained value is equals to expected value or not. This assertion will return true in the case if the expected value is the same as the actual value else returns false.
You can use a so called data provider. Like this:
/**
* @dataProvider providerPersonData
*/
public function testPerson($name, $age) {
// test something ...
}
public function providerPersonData() {
// test with this values
return array(
array('foo', 36),
array('bar', 99),
// ...
);
}
You define the data provider using the @dataProvider
annotation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With