【问题标题】:Why this code from Fest showing error?为什么 Fest 的这段代码显示错误?
【发布时间】:2013-06-08 11:47:52
【问题描述】:

我正在努力学习 Java Fest。我从:http://docs.codehaus.org/display/FEST/Getting+Started

import org.testng.annotations.*;
import org.fest.swing.fixture.FrameFixture;

public class FirstGUITest {

  private FrameFixture window;

  @BeforeClass public void setUpOnce() {
    FailOnThreadViolationRepaintManager.install();
  }

  @BeforeMethod public void setUp() {
    MyFrame frame = GuiActionRunner.execute(new GuiQuery<MyFrame>() {
        protected MyFrame executeInEDT() {
          return new MyFrame(); 
        }
    });
    window = new FrameFixture(frame);
    window.show(); // shows the frame to test
  }

  @AfterMethod public void tearDown() {
    window.cleanUp();
  }

  @Test public void shouldCopyTextInLabelWhenClickingButton() {
    window.textBox("textToCopy").enterText("Some random text");
    window.button("copyButton").click();
    window.label("copiedText").requireText("Some random text");
  }
}

在 Eclipse 中,此代码显示一些错误。我必须导入

import org.fest.swing.edt.FailOnThreadViolationRepaintManager;

尽管这部分显示错误:

  @BeforeMethod public void setUp() {
    MyFrame frame = GuiActionRunner.execute(new GuiQuery<MyFrame>() {
        protected MyFrame executeInEDT() {
          return new MyFrame(); 
        }
    });

它在 Myframe 上显示错误。谁能解释一下这是什么原因?提前致谢。

编辑:我将以下 jar 与我的项目相关联:

  1. fest-swing-testng-1.2
  2. fest-swing-1.2

错误是:

MyFrame can not be resolved to a type.

【问题讨论】:

  • 您应该发布实际的错误消息。
  • 错误是“MyFrame 无法解析为类型。”
  • 这表明您可能缺少导入或类。 MyFrame 是 fest 库的核心类型吗?如果是这样,你导入它吗?如果不是,它是您创建的类吗?
  • fest 是否带有 API?我会检查一下,因为它应该告诉您 MyFrame 类的完全限定名称,可能还有它的 jar 文件。
  • Swing GUI 对象应event dispatch thread上构造和操作。

标签: java swing testing applet fest


【解决方案1】:

首先你应该使用 AssertJ Swing; FEST 已过时,不再维护。但由于 AssertJ Swing 共享类似的语法,因此转换将很容易。

MyFrame 不是 FEST/AssertJ-Swing 的一部分。它应该是您编写应用程序的框架。因此,请改用 JFrame 或您拥有的任何框架实现。

看看AssertJ Examples(很抱歉发布有关 AssertJ 的帖子,但如果您想坚持使用 FEST,应该可以根据您的目的调整代码)。它包含编译版本中的示例 - 因此您可以查看并尝试一下 AssertJ Swing/FEST 是否适合您。

【讨论】:

    猜你喜欢
    • 2017-11-25
    • 2020-08-01
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多