Netbeans:如何更改用于识别 testSuites 的命名模式
我有许多带有“Tests”后缀的 JUNIT TestSuite。 Eclipse 识别静态 suite() 方法并在包资源管理器中提供运行测试选项。然而,对于 NetBeans 却并非如此,它只为我提供了默认的“运行”上下文菜单选项。但是我注意到它确实识别任何使用“TestSuite”作为后缀作为测试套件的类。我是 NB 7.0 的新手,无法了解如何更改模式或如何使 NB 以与 Eclipse 相同的方式工作。
I have numerous JUNIT TestSuites that have a "Tests" suffix. Eclipse recognises the static suite() method and makes a run test option available in package explorer. However the same is not true with NetBeans which only gives me the default Run context menu option. However i noticed that it does recognize any class that uses "TestSuite" as a suffix as a Tests suite. I am new to NB 7.0 and am unable to find out how to alter the pattern or some how make NB work in the same way as Eclipse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,实际上,我在努力解决自己的问题时发现了这一点。 Vanilla NetBeans使用ant,所以这个问题实际上是一个ant问题。如果您查看项目的目录,我们会看到有 build.xml 文件。这是指示 ant 做什么的主要文件。如果我们查看该文件内部,我们会发现它的主要功能是简单地; nbproject/build-impl.xml 文件。所以,我们需要的东西就在这里。我们可以使用此文件来覆盖默认实现的功能。
如果您深入研究 build-impl.xml 文件,您将看到 junit 部分。查找此部分:
这是实际运行测试的部分,它位于一小块 xml 中,这正是我们所需要的,因为我们只想覆盖一小部分。很明显,您可以看到我们仅匹配(递归)与模式“*Test.java”匹配的文件名。因此,在您的情况下,您将编辑(或添加)模式“TestSuite.java”。不过,不要将此行添加到该文件中,它可能会被删除,因为这是一个自动生成的文件。相反,将整个部分复制到实际的 build.xml 文件中,我认为它需要粘贴在上方。指令,因此它将优先。 (也许不行,如果不起作用,请在下面尝试一下。)
现在,这是一个棘手的问题,NetBeans 有一个自定义 junit 运行程序,即>。标签。如果不进一步深入了解如何传递参数,我们不知道如何向其添加参数,但对于您的情况,这很好,我们实际上不需要添加一,我们只需编辑它就可以使其工作。
这应该可能为你做。现在,它将匹配任何包含单词 test 的内容,而不仅仅是以单词 test 结尾的内容。
Ok, actually, I figured it out, while digging around trying to solve my own problem. Vanilla NetBeans uses ant, so this question is actually an ant question. If you look in the project's directory, we see that there is the build.xml file. This is the primary file that instructs ant what to do. If we look inside the file, we see that it's primary function is to simply <import /> the nbproject/build-impl.xml file. So, what we need is in here. We can use this file to override the functionality of the default implementation.
If you dig down into the build-impl.xml file, you'll come upon the junit section. Look for this section:
This is the section that actually runs the tests, and it's in a small block of xml, which is exactly what we need, because we're only trying to override one small bit. As is hopefully obvious, you can see we're only matching (recursively) file names that match the patter "*Test.java". So, in your case you would edit (or add) to that the pattern "TestSuite.java". Don't add this line to that file though, it might get hosed, as this is an automatically generated file. Instead, copy that whole bit to the actual build.xml file, and I think it needs to be pasted above the <import /> directive so it will take precedence. (Maybe not, try it below as well if that doesn't work.)
Now, here's the tricky bit, NetBeans has a custom junit runner, the <j2seproject3:junit /> tag. Without digging down even further to see how to pass it arguments, we don't know exactly how to add arguments to it, but for your case, this is fine, we don't really need to add one, we can make it work by just editing the one.
This should likely do it for you. Now it will match anything that has the word test in it, and not just stuff that ends with the word test.
如果您使用的是 ant 项目,则需要进入项目目录中的 ant 文件,并找到定位测试的 ant 命令。上次我检查时(几年前),它正在寻找的文件名模式是硬编码的。
If you're using an ant project, you need to go into the ant files in the project directory, and find the ant commands that locate the tests. Last time I checked (a couple of years ago), the file name pattern that it was looking for was hard coded.