在 Netbeans 中的测试中找不到公共方法(无法编译的代码)(但可以从命令行运行)

发布于 2025-01-14 04:10:32 字数 832 浏览 4 评论 0原文

我想测试已经有测试的类中的公共方法。

public class LocalDb {
  private final static LocalDb INSTANCE = new LocalDb();

 public synchronized static LocalDb getInstance() {
   ...
   return INSTANCE;
 }
 
 private LocalDb() {
    }

 public boolean getSomething(){
}

 public void justForTest(){
       
 }

}

然而,在我的测试中,当我执行 LocalDb.getInstance().justForTest() 时,我得到 symbol not findLocalDb.getInstance().getSomething()<找到 /code> 并且此测试类中的其他测试运行良好。

两者之间的唯一区别是 getSomething 是几个月前创建的,而 justForTest 刚刚创建。在测试类中无法“找到”新方法,但可以在代码中的其他任何地方找到它。

编辑:如果我从命令行使用 mvn -Dtest=LocalDbTest#testJustForTest test 我不会收到 Netbeans 中出现的“无法编译的代码:找不到符号”错误,并且测试会成功。

我还尝试删除项目“目标”目录,“清理并构建”项目,重新启动 Netbeans,重新启动计算机。

怎么了 ?我正在使用 Netbeans 12.8。

任何帮助表示赞赏

I want to test a public method from a class that already has tests.

public class LocalDb {
  private final static LocalDb INSTANCE = new LocalDb();

 public synchronized static LocalDb getInstance() {
   ...
   return INSTANCE;
 }
 
 private LocalDb() {
    }

 public boolean getSomething(){
}

 public void justForTest(){
       
 }

}

However in my test, when I do LocalDb.getInstance().justForTest() I get symbol not found whereas LocalDb.getInstance().getSomething() is found and other tests within this Test Class run fine.

The only difference between the two is that getSomething was created months ago, whereas justForTest has just been created. No new method can be "found" in test class, whereas it can be found anywhereelse in code.

Edit : If I use from the command line mvn -Dtest=LocalDbTest#testJustForTest test I don't get the "Uncompilable code : cannot find symbol" error I get in Netbeans and the test succeeds.

I also tried to delete the project "target" directory, to "clean and build" the project, to restart Netbeans, to reboot the computer.

What is happening ? I am using Netbeans 12.8.

Any help appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文