[英]PHPStorm, unit testing the current class
I'm trying to migrate from NetBeans to PHPStorm and the thing I cannot figure out is: how do I run my test suite for the current class (which ever that might be) without creating a run configuration for each class separately? 我正在尝试从NetBeans迁移到PHPStorm,而我无法弄清楚的是:如何在不为每个类单独创建运行配置的情况下为当前类(可能是哪个)运行我的测试套件?
In NetBeans, you can run your entire suite with Alt+F6 or run the current class with just F6. 在NetBeans中,您可以使用Alt + F6运行整个套件,或仅使用F6运行当前类。 This enables you to run just the tests you need and not your entire suite all the time which is obviously a time saver.
这使您可以只运行所需的测试而不是整个套件,这显然可以节省时间。
I cannot figure out how to do this in PHPStorm without creating a new run configuration for each and every class in the project which I obviously do not want to do. 我无法弄清楚如何在PHPStorm中执行此操作而不为项目中的每个类创建新的运行配置,我显然不想这样做。
First You have to tell PHPStorm where do You store your tests: 首先您必须告诉PHPStorm您存储测试的位置:
You can even right click on a single test method and choose "Run" (or Debug), Same for any test folder (if you have nested tests directories). 您甚至可以右键单击单个测试方法并为任何测试文件夹选择“运行”(或调试),相同(如果您有嵌套测试目录)。
This thread helped me a lot and I was thankful for Jakub's answer however I had to do additional digging so I thought I would try to take it a bit further: 这个帖子给了我很多帮助,我很感谢Jakub的答案,但我不得不做更多的挖掘,所以我想我会尝试进一步研究它:
File > settings > Directories 文件>设置>目录
File > Settings > Languages & Frameworks > PHP 文件>设置>语言和框架> PHP
File > Settings > Languages & Frameworks > PHP > PHPUnit 文件>设置>语言和框架> PHP> PHPUnit
assuming your using composer select use Composer autoloader and set the path to yourprojectroot/vendor/autoload.php
假设您使用composer选择使用Composer自动加载器并设置您的
yourprojectroot/vendor/autoload.php
的路径
or you can select Path to phpunit.phar and navigate to vendor/bin/phpunit
, then check the box next to Default bootstrap file and make that the path to vendor/autoload.php
或者您可以选择路径到phpunit.phar并导航到
vendor/bin/phpunit
,然后选中Default bootstrap文件旁边的框并将其设为vendor/autoload.php
的路径
Open any phpunit test file in the editor and press Ctrl Shift F10 to run it 在编辑器中打开任何phpunit测试文件,然后按Ctrl Shift F10运行它
Additional Tips : Since posting this and using the feature I learned a few more helpful things and thought I would just add them here: 其他提示 :自从发布此功能并使用该功能后,我学到了一些更有用的东西,并认为我会在这里添加它们:
In the project file explorer if you select any test directory or test file and do Ctrl Shift F10 it will run that file or all test files in the directory. 在项目文件资源管理器中,如果选择任何测试目录或测试文件并按Ctrl Shift F10 ,它将运行该文件或目录中的所有测试文件。
Shift F10 - will re-run whatever test you ran last, so if you are doing TDD and previously executed the test and you are working in the class being tested you can make a change and just press Shift F10 after each change and it re-runs the previously run test, no need to select the test to re-run it. Shift F10 - 将重新运行您最后运行的任何测试,因此如果您正在进行TDD并且之前执行了测试并且您正在测试的类中工作,您可以进行更改,只需在每次更改后按Shift F10并重新执行运行以前运行的测试,无需选择测试重新运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.