0

我正在尝试学习 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. 巨星-摇摆-testng-1.2
  2. 巨星摇摆-1.2

错误是:

MyFrame can not be resolved to a type.
4

1 回答 1

0

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

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

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

于 2015-07-23T17:39:44.930 回答