我是PHPUnit测试的新手,所以稍后我会对它提出很多疑问,但首先,一步一步走。
我试图从netbeans网站关注以下this tutorial。
不幸的是,文档有点过时了,我想不太精确。
我在Win7 Ultimate 64bit上使用Netbeans 8.0.2
所以,我创建了一个新项目,并在其下Calculator.php
并复制了教程中的代码。
然后我右键点击它,比如,工具 - >创建测试。在我的test
目录中,骨架生成器创建CalculatorTest
。
文档忘记提及创建boostrap
以包含Calculator.php
进行测试,但不要卡在上面,我做了。
现在,我右键点击Calculator.php
并说Test
。结果不是我所期望的。
测试结果窗口显示:No test executed
,而右侧显示:
Perhaps error occurred, verify in Output window.
很抱歉这一大堆代码,我只想确定,你看到我做了什么,所以这里是输出窗口的内容(见下文)。
我做错了什么,我该如何解决这个问题?
"D:\PHP\php.exe" "D:\bin\phpunit.phar" "--colors" "--log-junit" "C:\Users\Lenovo\AppData\Local\Temp\nb-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.