图 4. 糟糕的极端例子
当然,使用 TestNG-Abbot 测试这种情况非常简单,不是吗?我所做的仅仅是将空值传送到 TextComponentFixture 中,按下按钮(通过对 ButtonFixture 使用 click 方法)并插入 “Please enter a valid word” 响应!
清单 4. 测试一个极端例子:如果有人没有输入单词就按下了按钮该怎么办?
@Test
public void assertNoWordPresentInvalidText() {
TextComponentFixture text1 = new TextComponentFixture(this.fixture,
"wordValue");
text1.enterText("");
ButtonFixture bfix = new ButtonFixture(this.fixture, "findWord");
bfix.click();
LabelFixture fix = new LabelFixture(this.fixture, "definition");
fix.shouldHaveThisText("Please enter a valid word");
}
|
如清单 4 所示,一旦理解了获得所需 GUI 组件的引用时,事情并不是很困难。最后一步是检验其他 糟糕的极端例子 —— 输入了无效的单词。这个过程与 清单 1和 清单 3非常相似:仅仅是将所需的 String 传递到 TextComponentFixture 对象,单击,然后插入特定的文本。如清单 5 所示:
清单 5. 轻松验证另一个极端例子!
@Test
public void assertNoWordPresentInvalidText() {
TextComponentFixture text1 = new TextComponentFixture(this.fixture,
"wordValue");
text1.enterText("Ha77");
ButtonFixture bfix = new ButtonFixture(this.fixture, "findWord");
bfix.click();
|










