简体   繁体   English

如何在netbeans中组织不同的Java源文件夹(以进行测试)?

[英]How to organize different java source folders in netbeans (for testing)?

I am developing a project in Netbeans (8.0.2) that uses JUnit (4.x) for testing application code (in a Netbeans module). 我正在NetBeans(8.0.2)中开发一个项目,该项目使用JUnit(4.x)来测试应用程序代码(在Netbeans模块中)。 In the same module I also have some integration tests. 在同一模块中,我还进行了一些集成测试。 I found a way to separate application code, unit tests and integration tests by putting the latter into a separate folder under MODULE_PATH\\test\\qa-functional\\src. 我找到了一种将应用程序代码,单元测试和集成测试分离的方法,方法是将后者放在MODULE_PATH \\ test \\ qa-functional \\ src下的单独文件夹中。 By that, the Netbeans IDE puts those three semantical different kinds of classes into individual folders: 这样,Netbeans IDE会将这三种语义上不同的类放入单独的文件夹中:

Netbeans项目视图具有折叠的源,单元和功能测试包

The problem is, my functional tests tend to grow complex, so I would prefer to have them, well, unit tested. 问题是,我的功能测试趋向于变得复杂,所以我宁愿对它们进行单元测试。 However if create a unit test (in the Unit Test Package) for a class of the functional test package, the test does not compile. 但是,如果为功能测试包的类创建一个单元测试(在“单元测试包”中),则该测试不会编译。 Seems to be some class path issues. 似乎是一些类路径问题。

Netbeans项目视图具有扩展的源,单元和功能测试包。 IntegrationTestTest.java错误

I know I can put the unit test of the functional test in the functional test package as well (and I will do so if this question does not provide me with some solution), but anyway, is there a way to solve this in Netbeans? 我知道我也可以将功能测试的单元测试放入功能测试包中(如果这个问题不能为我提供解决方案,我会这样做),但是无论如何,在Netbeans中有没有办法解决这个问题?

I found a bad solution, changing the order of ant targets in common.xml (in line 610 of NB 8.0.2). 我发现了一个不好的解决方案,更改了common.xml中的ant目标顺序(在NB 8.0.2的610行中)。 But that is obiously not portable, changes with a new version of Netbeans,.. So not really a solution. 但这显然是不可移植的,但是随着新版本的Netbeans的改变,..并不是真正的解决方案。 See details in Netbeans Forum: Classpath problem when unit testing functional tests 请参阅Netbeans论坛中的详细信息单元测试功能测试时的类路径问题

In Eclipse, I would simply add a new source folder on the Java build path. 在Eclipse中,我只需在Java构建路径上添加一个新的源文件夹。 But that mechanism does not exist in Netbeans? 但是Netbeans中不存在这种机制吗? For clearification, I added a screenshot. 为了清楚起见,我添加了一个屏幕截图。

Eclipse软件包浏览器,带有用于src和功能测试代码的单独的单元测试文件夹

Thanks in advance for your help. 在此先感谢您的帮助。

You are are trying to do a wrong thing : 您正在尝试做错事

  • unit tests should verify the smallest possible functionality, eg that a method is producing the expected result 单元测试应验证可能的最小功能,例如方法正在产生预期的结果
  • functional tests in NetBeans represent integration tests, tests when you treat the application as a black box NetBeans中的功能测试代表集成测试,将应用程序视为黑匣子时的测试

It does not make sense to "unit test" the functionality in the "functional tests". “功能测试”中的功能“单元测试”没有意义。 NetBeans treats the tests folders independent so that they are not on each other's classpath, that's why it does not work in NetBeans. NetBeans独立对待测试文件夹,以使它们不在彼此的类路径上,这就是为什么它在NetBeans中不起作用的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM