douheng8629 2015-01-22 15:24 采纳率: 100%
浏览 56

在Netbeans中使用PHPUnit测试

I am really new to PHPUnit testing, so I will have a lot of question about it later, but first, go step by step.

I'v tried to follow the following this tutorial from netbeans site.

Unluckily, the documentation is a littlebit outdated, and not so precise I think.

I am using Netbeans 8.0.2 on Win7 Ultimate 64bit

So, I've created a new project, and under that a Calculator.php and copied the code from the tutorial.

Then I right click on that, say, Tools -> Create Tests. In my test directory, the skeleton generator creates the CalculatorTest.

Documentation forgot to mention to create a boostrap to include the Calculator.php for the test, but don't get stuck on it, I did it.

Now, I am right click on the Calculator.php and says, Test. The result is not that what I am expected.

The test results window says: No test executed, while the on the right:

Perhaps error occurred, verify in Output window.

Sorry for this big bunch of code, I've just want to be sure, you are see what I do, so here is the content of the output window (see below).

What do I am doing wrong, how can I solve this problem?

"D:\PHP\php.exe" "D:\bin\phpunit.phar" "--colors" "--log-junit" "C:\Users\Lenovo\AppData\Local\Temp
b-phpunit-log.xml" "--bootstrap" "D:\Apache\htdocs\unittest\test\bootstrap.php" "C:\Users\Lenovo\AppData\Roaming\NetBeans\8.0\phpunit\NetBeansSuite.php" "--run=D:\Apache\htdocs\unittest\test\CalculatorTest.php"
PHPUnit 4.4.2 by Sebastian Bergmann.

....PHP SebastianBergmann\Comparator\ComparisonFailure:  Failed asserting that 3 matches expected 4. in phar://D:/bin/phpunit.phar/sebastian-comparator/NumericComparator.php on line 99
PHP Stack trace:
PHP   1. {main}() D:\bin\phpunit.phar:0
PHP   2. PHPUnit_TextUI_Command::main() D:\bin\phpunit.phar:619
PHP   3. PHPUnit_TextUI_Command->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:103
PHP   4. PHPUnit_TextUI_TestRunner->doRun() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:151
PHP   5. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/TestRunner.php:388
PHP   6. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
PHP   7. PHPUnit_Framework_TestCase->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
PHP   8. PHPUnit_Framework_TestResult->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:687
PHP   9. PHPUnit_Framework_TestCase->runBare() phar://D:/bin/phpunit.phar/phpunit/Framework/TestResult.php:609
PHP  10. PHPUnit_Framework_TestCase->runTest() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:731
PHP  11. ReflectionMethod->invokeArgs() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:846
PHP  12. CalculatorTest->testAdd5() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:846
PHP  13. PHPUnit_Framework_Assert::assertEquals() D:\Apache\htdocs\unittest\test\CalculatorTest.php:81
PHP  14. PHPUnit_Framework_Assert::assertThat() phar://D:/bin/phpunit.phar/phpunit/Framework/Assert.php:490
PHP  15. PHPUnit_Framework_Constraint_IsEqual->evaluate() phar://D:/bin/phpunit.phar/phpunit/Framework/Assert.php:2214
PHP  16. SebastianBergmann\Comparator\NumericComparator->assertEquals() phar://D:/bin/phpunit.phar/phpunit/Framework/Constraint/IsEqual.php:129
PHP PHPUnit_Framework_ExpectationFailedException:  Failed asserting that 3 matches expected 4. in phar://D:/bin/phpunit.phar/phpunit/Framework/Constraint/IsEqual.php on line 135
PHP Stack trace:
PHP   1. {main}() D:\bin\phpunit.phar:0
PHP   2. PHPUnit_TextUI_Command::main() D:\bin\phpunit.phar:619
PHP   3. PHPUnit_TextUI_Command->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:103
PHP   4. PHPUnit_TextUI_TestRunner->doRun() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:151
PHP   5. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/TestRunner.php:388
PHP   6. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
PHP   7. PHPUnit_Framework_TestCase->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
PHP   8. PHPUnit_Framework_TestResult->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:687
PHP   9. PHPUnit_Framework_TestCase->runBare() phar://D:/bin/phpunit.phar/phpunit/Framework/TestResult.php:609
PHP  10. PHPUnit_Framework_TestCase->runTest() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:731
PHP  11. ReflectionMethod->invokeArgs() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:846
PHP  12. CalculatorTest->testAdd5() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:846
PHP  13. PHPUnit_Framework_Assert::assertEquals() D:\Apache\htdocs\unittest\test\CalculatorTest.php:81
PHP  14. PHPUnit_Framework_Assert::assertThat() phar://D:/bin/phpunit.phar/phpunit/Framework/Assert.php:490
PHP  15. PHPUnit_Framework_Constraint_IsEqual->evaluate() phar://D:/bin/phpunit.phar/phpunit/Framework/Assert.php:2214
PHP PHPUnit_Framework_ExpectationFailedException:  Failed asserting that 3 matches expected 4. in phar://D:/bin/phpunit.phar/phpunit/Framework/Constraint/IsEqual.php on line 135
PHP Stack trace:
PHP   1. {main}() D:\bin\phpunit.phar:0
PHP   2. PHPUnit_TextUI_Command::main() D:\bin\phpunit.phar:619
PHP   3. PHPUnit_TextUI_Command->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:103
PHP   4. PHPUnit_TextUI_TestRunner->doRun() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:151
PHP   5. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/TestRunner.php:388


PHPUnit_Framework_ExpectationFailedException: Failed asserting that 3 matches expected 4. in phar://D:/bin/phpunit.phar/phpunit/Framework/Constraint/IsEqual.php on line 135

Call Stack:
    0.0300     384472   1. {main}() D:\bin\phpunit.phar:0
    0.0340     589312   2. PHPUnit_TextUI_Command::main() D:\bin\phpunit.phar:619
    0.0340     592992   3. PHPUnit_TextUI_Command->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:103
    0.3690    1760968   4. PHPUnit_TextUI_TestRunner->doRun() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:151
    0.3860    2057496   5. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/TestRunner.php:388
    0.4100    2068840   6. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
    0.8230    2443240   7. PHPUnit_Framework_TestCase->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
    0.8250    2443208   8. PHPUnit_Framework_TestResult->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:687
    0.8290    2443952   9. PHPUnit_Framework_TestCase->runBare() phar://D:/bin/phpunit.phar/phpunit/Framework/TestResult.php:609
    0.8941    2538768  10. PHPUnit_Framework_TestCase->onNotSuccessfulTest() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:816

F

SebastianBergmann\Comparator\ComparisonFailure: Failed asserting that 3 matches expected 4. in phar://D:/bin/phpunit.phar/sebastian-comparator/NumericComparator.php on line 99

Call Stack:
    0.0300     384472   1. {main}() D:\bin\phpunit.phar:0
    0.0340     589312   2. PHPUnit_TextUI_Command::main() D:\bin\phpunit.phar:619
    0.0340     592992   3. PHPUnit_TextUI_Command->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:103
    0.3690    1760968   4. PHPUnit_TextUI_TestRunner->doRun() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:151
    0.3860    2057496   5. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/TestRunner.php:388
    0.4100    2068840   6. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
    0.8230    2443240   7. PHPUnit_Framework_TestCase->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
    0.8250    2443208   8. PHPUnit_Framework_TestResult->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:687
    0.8290    2443952   9. PHPUnit_Framework_TestCase->runBare() phar://D:/bin/phpunit.phar/phpunit/Framework/TestResult.php:609
    0.8550    2474128  10. PHPUnit_Framework_TestCase->runTest() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:731
    0.8550    2474600  11. ReflectionMethod->invokeArgs() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:846
    0.8550    2474616  12. CalculatorTest->testAdd5() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:846
    0.8560    2474712  13. PHPUnit_Framework_Assert::assertEquals() D:\Apache\htdocs\unittest\test\CalculatorTest.php:81
    0.8560    2475072  14. PHPUnit_Framework_Assert::assertThat() phar://D:/bin/phpunit.phar/phpunit/Framework/Assert.php:490
    0.8570    2475072  15. PHPUnit_Framework_Constraint_IsEqual->evaluate() phar://D:/bin/phpunit.phar/phpunit/Framework/Assert.php:2214
    0.8661    2477440  16. SebastianBergmann\Comparator\NumericComparator->assertEquals() phar://D:/bin/phpunit.phar/phpunit/Framework/Constraint/IsEqual.php:129



PHPUnit_Framework_ExpectationFailedException: Failed asserting that 3 matches expected 4. in phar://D:/bin/phpunit.phar/phpunit/Framework/Constraint/IsEqual.php on line 135

Call Stack:
    0.0300     384472   1. {main}() D:\bin\phpunit.phar:0
    0.0340     589312   2. PHPUnit_TextUI_Command::main() D:\bin\phpunit.phar:619
    0.0340     592992   3. PHPUnit_TextUI_Command->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:103
    0.3690    1760968   4. PHPUnit_TextUI_TestRunner->doRun() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:151
    0.3860    2057496   5. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/TestRunner.php:388
    0.4100    2068840   6. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
    0.8230    2443240   7. PHPUnit_Framework_TestCase->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
    0.8250    2443208   8. PHPUnit_Framework_TestResult->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:687
    0.8290    2443952   9. PHPUnit_Framework_TestCase->runBare() phar://D:/bin/phpunit.phar/phpunit/Framework/TestResult.php:609
    0.8550    2474128  10. PHPUnit_Framework_TestCase->runTest() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:731
    0.8550    2474600  11. ReflectionMethod->invokeArgs() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:846
    0.8550    2474616  12. CalculatorTest->testAdd5() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:846
    0.8560    2474712  13. PHPUnit_Framework_Assert::assertEquals() D:\Apache\htdocs\unittest\test\CalculatorTest.php:81
    0.8560    2475072  14. PHPUnit_Framework_Assert::assertThat() phar://D:/bin/phpunit.phar/phpunit/Framework/Assert.php:490
    0.8570    2475072  15. PHPUnit_Framework_Constraint_IsEqual->evaluate() phar://D:/bin/phpunit.phar/phpunit/Framework/Assert.php:2214



PHPUnit_Framework_ExpectationFailedException: Failed asserting that 3 matches expected 4. in phar://D:/bin/phpunit.phar/phpunit/Framework/Constraint/IsEqual.php on line 135

Call Stack:
    0.0300     384472   1. {main}() D:\bin\phpunit.phar:0
    0.0340     589312   2. PHPUnit_TextUI_Command::main() D:\bin\phpunit.phar:619
    0.0340     592992   3. PHPUnit_TextUI_Command->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:103
    0.3690    1760968   4. PHPUnit_TextUI_TestRunner->doRun() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:151
    0.3860    2057496   5. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/TestRunner.php:388
    0.4100    2068840   6. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
    0.8230    2443240   7. PHPUnit_Framework_TestCase->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
    0.8250    2443208   8. PHPUnit_Framework_TestResult->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:687
    0.8290    2443952   9. PHPUnit_Framework_TestCase->runBare() phar://D:/bin/phpunit.phar/phpunit/Framework/TestResult.php:609
    0.8550    2474128  10. PHPUnit_Framework_TestCase->runTest() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:731



Time: 1 second, Memory: 4.00Mb

There was 1 failure:

1) CalculatorTest::testAdd5
Failed asserting that 3 matches expected 4.

D:\Apache\htdocs\unittest\test\CalculatorTest.php:81

FAILURES!
Tests: 5, Assertions: 5, Failures: 1.
PHP   6. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
PHP   7. PHPUnit_Framework_TestCase->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
PHP   8. PHPUnit_Framework_TestResult->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:687
PHP   9. PHPUnit_Framework_TestCase->runBare() phar://D:/bin/phpunit.phar/phpunit/Framework/TestResult.php:609
PHP  10. PHPUnit_Framework_TestCase->runTest() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:731
PHP PHPUnit_Framework_ExpectationFailedException:  Failed asserting that 3 matches expected 4. in phar://D:/bin/phpunit.phar/phpunit/Framework/Constraint/IsEqual.php on line 135
PHP Stack trace:
PHP   1. {main}() D:\bin\phpunit.phar:0
PHP   2. PHPUnit_TextUI_Command::main() D:\bin\phpunit.phar:619
PHP   3. PHPUnit_TextUI_Command->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:103
PHP   4. PHPUnit_TextUI_TestRunner->doRun() phar://D:/bin/phpunit.phar/phpunit/TextUI/Command.php:151
PHP   5. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/TextUI/TestRunner.php:388
PHP   6. PHPUnit_Framework_TestSuite->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
PHP   7. PHPUnit_Framework_TestCase->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestSuite.php:716
PHP   8. PHPUnit_Framework_TestResult->run() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:687
PHP   9. PHPUnit_Framework_TestCase->runBare() phar://D:/bin/phpunit.phar/phpunit/Framework/TestResult.php:609
PHP  10. PHPUnit_Framework_TestCase->onNotSuccessfulTest() phar://D:/bin/phpunit.phar/phpunit/Framework/TestCase.php:816
Done.
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作