Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse 具有多个类测试的JUnitLaunch快捷方式_Eclipse_Eclipse Plugin_Junit - Fatal编程技术网

Eclipse 具有多个类测试的JUnitLaunch快捷方式

Eclipse 具有多个类测试的JUnitLaunch快捷方式,eclipse,eclipse-plugin,junit,Eclipse,Eclipse Plugin,Junit,当我执行这段代码时: Object[] segments = new Object[2]; segments[0] = // JUnit Test Class 1 segments[1] = // JUnit Test Class 2 TreePath treepath = new TreePath(segments); TreeSelection treeselection = new TreeSelection(treepath); JUnitLaunchShortcut j = new

当我执行这段代码时:

Object[] segments = new Object[2];
segments[0] = // JUnit Test Class 1
segments[1] = // JUnit Test Class 2

TreePath treepath = new TreePath(segments);
TreeSelection treeselection = new TreeSelection(treepath);

JUnitLaunchShortcut j = new JUnitLaunchShortcut();
j.launch(treeselection, ILaunchManager.RUN_MODE);
Eclipse/JUnit插件仅执行JUnit测试类2,可能执行两个测试类,但仅在JUnit查看最后一个测试类时显示(可能)


你怎么想?如何“启动”所有测试类?

正如您在评论中所说,JUnit eclipse插件不支持配置中的多个选择。但是,
org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate
确实支持多个测试启动。当您在JUnit插件中选择一个项目/包/测试类,并选择RunasJUnitTest时,它会将配置传递给JUnitLaunchConfigurationDelegate,并在其中评估要运行的测试。如果有,它会调用RemoteTestRunner,如下所示:

RemoteTestRunner -test TestClass
RemoteTestRunner -testfile testNamesxxxx.txt
如果它找到多个文件,则运行方式如下:

RemoteTestRunner -test TestClass
RemoteTestRunner -testfile testNamesxxxx.txt
其中testNamesxxx.test是一个包含要运行的测试列表的文件,例如:

uk.co.farwell.junit.parameters.ParameterTest
uk.co.farwell.junit.run.AllTests
uk.co.farwell.junit.run.Class1Test
此文件是在临时目录中创建的。因此,一种可能的探索方法是扩展JUnitLanchConfigurationDelegate并重写evaluateTests方法,该方法具有如下签名:

protected IMember[] evaluateTests(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {

您还需要知道如何通过ILaunchConfiguration与测试列表进行通信,但您也可以为插件扩展此功能。

正如您在评论中所说,JUnit插件for eclipse不支持配置中的多项选择。但是,
org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate
确实支持多个测试启动。当您在JUnit插件中选择一个项目/包/测试类,并选择RunasJUnitTest时,它会将配置传递给JUnitLaunchConfigurationDelegate,并在其中评估要运行的测试。如果有,它会调用RemoteTestRunner,如下所示:

RemoteTestRunner -test TestClass
RemoteTestRunner -testfile testNamesxxxx.txt
如果它找到多个文件,则运行方式如下:

RemoteTestRunner -test TestClass
RemoteTestRunner -testfile testNamesxxxx.txt
其中testNamesxxx.test是一个包含要运行的测试列表的文件,例如:

uk.co.farwell.junit.parameters.ParameterTest
uk.co.farwell.junit.run.AllTests
uk.co.farwell.junit.run.Class1Test
此文件是在临时目录中创建的。因此,一种可能的探索方法是扩展JUnitLanchConfigurationDelegate并重写evaluateTests方法,该方法具有如下签名:

protected IMember[] evaluateTests(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {

您还需要知道如何通过iLunchConfiguration与测试列表进行通信,但您也可以为您的插件扩展此功能。

请回答您之前的一些问题。我检查了JUnitLanchShortcut代码,并验证了代码为IStructuredSelection和call launch(Object[]元素,字符串模式)强制转换了TreeSelection ... 在整个过程中,ILaunchConfigurationWorkingCopy只能为一个测试设置属性,但我需要N个测试…:(我如何创建ILaunchConfigurationWorkingCopy以运行多个测试?!或者,我如何为VMArg添加多个ILaunchConfigurationWorkingCopy?经过许多小时后,我认为不可能实现我想要的功能…Eclipse的RunConfiguration不支持针对我选择的多个测试用例运行!只运行一个TestClass或一个项目、软件包或者SourceFolder,没有从多个包中运行多个测试用例。(我很难过:()请回答您以前的一些问题。我检查了JUnitLanchShortcut代码,并验证了代码是否为IStructuredSelection和call launch(Object[]元素,字符串模式)强制转换树选择)…在此整个过程中,ILaunchConfigurationWorkingCopy只能为一个测试设置属性,但我需要N个测试…:(我如何创建ILaunchConfigurationWorkingCopy以运行多个测试?!或者,我如何为VMArg添加多个ILaunchConfigurationWorkingCopy?经过许多小时后,我认为不可能实现我想要的功能…Eclipse的RunConfiguration不支持针对我选择的多个测试用例运行!只运行一个TestClass或一个项目、软件包或者SourceFolder,不运行多个包中的多个测试用例。(我很难过:()听起来很简单,但非常困难…很难理解如何扩展ILaunchConfiguration,我无法理解如何添加更多测试,然后调用RemoteTestRunner…:(您好,Matthew,我扩展了JUnitLaunchConfigurationDelegate并覆盖了evaluateTests方法,如您所说……在我创建之后,但是如果我用项目、包或类的HandleIdentifier填充ATTR_TEST_CONTAINER属性,那么启动器将执行该项目、包或类上的测试,而不是我的overr返回的测试。)ide evaluateTests…如果我不填充该属性,Eclipse将返回“启动配置的输入类型不存在”…好的,我再次检查我的代码,发现有错误的行ILaunch launch=wc.launch(ILaunchManager.RUN_MODE,null);我将其更改为ILaunch launch=new launch(wc,ILaunchManager.RUN_MODE,null);之后,我检查testNamesxxxx.txt,它有我想要的测试名称…:)现在问题是JUnit没有运行:(,什么也没有发生,我认为问题在于Launch的创建…听起来很简单,但非常困难…很难理解如何扩展ILaunchConfiguration,我无法理解如何添加更多测试,然后调用RemoteTestRunner…:(您好,Matthew,我扩展了JUnitLaunchConfigurationDelegate并覆盖了evaluateTests方法,如您所说……在我创建之后,但是如果我用项目、包或类的HandleIdentifier填充ATTR_TEST_CONTAINER属性,那么启动器将执行该项目、包或类上的测试,而不是我的overr返回的测试。)ide evaluateTests…如果我不填充该属性,Eclipse将返回“启动配置的输入类型不存在”…好的,我再次检查我的代码,发现有错误的行ILaunch launch=wc.launch(ILaunchManager.RUN_MODE,null);我将其更改为ILaunch launch=new launch(wc,ILaunchManager.RUN_MODE,null);之后我检查testNamesxxxx.txt,它有我想要的测试名称…:)现在问题是JUnit没有运行:(,什么都没有发生,我认为问题是在创建Launch。。。