1

I have installed PHPUnit via Pear.

While I try testing via PHPUnit,even after giving the test file path it shows error: The system cannot find the path specified.

I have tried Sample code in : https://netbeans.org/kb/docs/php/phpunit.html?print=yes#installing-phpunit

<?php
class Calculator
{
    /**
     * @assert (0, 0) == 0
     * @assert (0, 1) == 1
     * @assert (1, 0) == 1
     * @assert (1, 1) == 2
     * @assert (1, 2) == 4
     */
    public function add($a, $b)
    {
        return $a + $b;
    }
}
?>

1 Answer 1

1

Not sure what your source file is called, but there are not any tests written in for the class. You used the generator, which has created the @asserts. Now, you need to generate the test class to use those. The PHPUnit Manual Skeleton Generator is then needed to run to produce the actual tests.

With your code, you have the sample @assert annotations for what should be simple to generate test cases. Therefore, you need to generate the test cases.

phpunit-skelgen --test Calculator

or for Namespaces (where Project is the name space)

phpunit-skelgen --test -- "project\Calculator" Calculator.php

Then you can see tests generated

/**
 * Generated from @assert (0, 0) == 0.
 */
public function testAdd() {
    $o = new Calculator;
    $this->assertEquals(0, $o->add(0, 0));
}

Finally, you can execute your tests:

 phpunit --bootstrap Calculator.php --verbose CalculatorTest
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.