在Netbeans中使用PHPUnit测试
我对PHPUnit测试真的很陌生,所以稍后我会有很多问题,但首先,一步一步地进行 我在netbeans网站上尝试了以下内容 不幸的是,文档有点过时,而且我认为不太准确 我在Win7 Ultimate 64位上使用Netbeans 8.0.2 因此,我创建了一个新项目,并在该项目下创建了一个在Netbeans中使用PHPUnit测试,php,unit-testing,netbeans,phpunit,Php,Unit Testing,Netbeans,Phpunit,我对PHPUnit测试真的很陌生,所以稍后我会有很多问题,但首先,一步一步地进行 我在netbeans网站上尝试了以下内容 不幸的是,文档有点过时,而且我认为不太准确 我在Win7 Ultimate 64位上使用Netbeans 8.0.2 因此,我创建了一个新项目,并在该项目下创建了一个Calculator.php,并从教程中复制了代码 然后我右键点击它,比如说,工具->创建测试。在我的test目录中,骨架生成器创建CalculatorTest 文档中忘记了创建一个boostrap来包含测试用
Calculator.php
,并从教程中复制了代码
然后我右键点击它,比如说,工具->创建测试。在我的test
目录中,骨架生成器创建CalculatorTest
文档中忘记了创建一个boostrap
来包含测试用的Calculator.php
,但是不要被卡住了,是我做的
现在,我右键单击Calculator.php
并说,Test
。结果并不是我所期望的那样
测试结果窗口显示:未执行任何测试
,而右侧显示:
可能发生错误,请在输出窗口中验证。
很抱歉,有这么多代码,我只是想确定一下,您是否看到了我所做的事情,下面是输出窗口的内容(见下文)
我做错了什么,如何解决这个问题
"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.
是否可以共享项目(将其上传到某处)?我认为您的配置(可能在引导文件中,可能在一些PHP配置中)导致测试的输出包含这些stracktraces,而NetBeans无法解析这些输出(因此“未执行测试”),您可以从这里下载它:仅三个文件,calc、test和boostratp,我故意在测试中添加了不好的结果,要检查的是Netbeans是否将其报告给我作为测试失败。如果我移除了它,那么我就用4个
通过的测试取回了面板。是这样吗,如何使用PHPUnit进行测试?检查。但即使使用Xdebug stacktrace,它也对我有效…@ladar:你是个救命恩人,我用它磕磕绊绊了1.5天。非常感谢你!