共享项目中的软件包后,Netbeans Tests [被Ant破坏]

时间:2019-01-07 16:59:34

标签: java unit-testing netbeans ant

我刚刚决定通过删除重复的类来简化项目。遵循this advice,了解如何在项目之间共享软件包,效果很好。

但是,它确实产生了一个奇怪的错误。在对整个项目(Alt + F6)进行测试时,在编译输出中出现一些错误:

ant -f ...nbPath\\CurrentProject -Dnb.internal.action.name=test -Dignore.failing.tests=true -Dnb.wait.for.caches=true test
init:
Deleting: ...nbPath\CurrentProject\build\built-jar.properties
deps-jar:
Updating property file: ...nbPath\CurrentProject\build\built-jar.properties
SharedPackageProject.init:
SharedPackageProject.deps-jar:
Updating property file: ...nbPath\CurrentProject\build\built-jar.properties
SharedPackageProject.init:
SharedPackageProject.deps-clean:
Updating property file: ...nbPath\SharedPackageProject\build\built-clean.properties
Deleting directory ...nbPath\SharedPackageProject\build
SharedPackageProject.clean:
Created dir: ...nbPath\SharedPackageProject\build\classes
Created dir: ...nbPath\SharedPackageProject\build\empty
Created dir: ...nbPath\SharedPackageProject\build\generated-sources\ap-source-output
Compiling 2 source files to ...nbPath\SharedPackageProject\build\classes
SharedPackageProject.compile:
Created dir: ...nbPath\SharedPackageProject\dist
Copying 1 file to ...nbPath\SharedPackageProject\build
Copy libraries to ...nbPath\SharedPackageProject\dist\lib.
Building jar: ...nbPath\SharedPackageProject\dist\SharedPackageProject.jar
To run this application from the command line without Ant, try:
java -jar "...nbPath\SharedPackageProject\dist\SharedPackageProject.jar"
SharedPackageProject.jar:
init:
deps-clean:
Updating property file: ...nbPath\CurrentProject\build\built-clean.properties
SharedPackageProject.init:
SharedPackageProject.deps-clean:
Updating property file: ...nbPath\CurrentProject\build\built-clean.properties
Deleting directory ...nbPath\SharedPackageProject\build
SharedPackageProject.clean:
Deleting directory ...nbPath\CurrentProject\build
clean:
Created dir: ...nbPath\CurrentProject\build\classes
Created dir: ...nbPath\CurrentProject\build\empty
Created dir: ...nbPath\CurrentProject\build\generated-sources\ap-source-output
Compiling 11 source files to ...nbPath\CurrentProject\build\classes
...nbPath\CurrentProject\src\CurrentProject\Dao.java:13: error: package SharedPackageProject does not exist
import SharedPackageProject.SmartDatabase;
...nbPath\CurrentProject\src\CurrentProject\Dao.java:22: error: cannot find symbol

接着是另一系列error: cannot find symbol,由于这些错误,测试无法运行。但是,如果我重新运行所有测试(再次按Alt + F6),它们将起作用!

这次没有错误,这是输出

ant -f ...nbPath\\CurrentProject -Dnb.internal.action.name=test -Dignore.failing.tests=true -Dnb.wait.for.caches=true test
init:
deps-jar:
Updating property file: ...nbPath\CurrentProject\build\built-jar.properties
SharedPackageProject.init:
SharedPackageProject.deps-jar:
Created dir: ...nbPath\SharedPackageProject\build
Updating property file: ...nbPath\CurrentProject\build\built-jar.properties
Created dir: ...nbPath\SharedPackageProject\build\classes
Created dir: ...nbPath\SharedPackageProject\build\empty
Created dir: ...nbPath\SharedPackageProject\build\generated-sources\ap-source-output
Compiling 2 source files to ...nbPath\SharedPackageProject\build\classes
SharedPackageProject.compile:
Created dir: ...nbPath\SharedPackageProject\dist
Copying 1 file to ...nbPath\SharedPackageProject\build
Copy libraries to ...nbPath\SharedPackageProject\dist\lib.
Building jar: ...nbPath\SharedPackageProject\dist\SharedPackageProject.jar
To run this application from the command line without Ant, try:
java -jar "...nbPath\SharedPackageProject\dist\SharedPackageProject.jar"
SharedPackageProject.jar:
Compiling 11 source files to ...nbPath\CurrentProject\build\classes
compile:
Created dir: ...nbPath\CurrentProject\build\test\classes
Compiling 4 source files to ...nbPath\CurrentProject\build\test\classes
compile-test:
Created dir: ...nbPath\CurrentProject\build\test\results
Testsuite: CurrentProject.DaoTest
...My tests output

通过对单个类运行测试(Ctrl + F6),然后再次运行所有测试(Alt + F6),我能够重现该错误。我认为这会触发干净的编译,从而提前清除文件夹。

我的猜测是Netbeans在我的测试类可以找到导入项目的jar之前尝试运行测试。而且,如果我重新运行,它会跳过清理编译以节省时间,而我当前的项目可以找到已经存在的另一个jar。

无论如何,这很烦人但很容易解决。

Product Version: NetBeans IDE 8.1 (Build 201510222201)
Updates: NetBeans IDE is updated to version NetBeans 8.1 Patch 1
Java: 1.8.0_25; Java HotSpot(TM) 64-Bit Server VM 25.25-b02
Runtime: Java(TM) SE Runtime Environment 1.8.0_25-b18

我将阅读有关Ant的内容,以了解构建过程。但任何帮助将不胜感激。

0 个答案:

没有答案