gpt4 book ai didi

java - 如何从 dsl 生成 UI 测试?

转载 作者:太空宇宙 更新时间:2023-11-03 11:05:40 26 4
gpt4 key购买 nike

我不确定这个问题属于 SO,因为它可能太宽泛了,但我不知道去哪里问(我没有找到更好的 stackexchange 站点)。

上下文

我正在使用 UiAutomator在 android 上写一些 Ui 测试。我创建了一些函数来简化测试的编写,就像文档中的那样

public void startMainActivityFromHomeScreen() {
/*Start the app from the home screen*/
}

作为开发人员,这很好用。但是非技术人员(契约(Contract)所有者)不能轻易使用此功能来编写测试。

需要

我正在寻找一种方法,让非技术用户可以使用我已经定义的函数编写一些脚本。这是一个虚拟示例(脚本格式和操作)

Suite: Launch the app twice from the home screen

Case: Launch the app for the first time
Do startMainActivityFromHomeScreen
Expect ...

Case: Launch the app for the second time
Do startMainActivityFromHomeScreen
Expect ...

这里重点是与java函数交互。我知道其他工具,例如 calabash但它不提供java接口(interface)。

当前方法

这是一个想法(没有实现)

  1. 将所有函数放在一个库中
  2. 编写一个 groovy dsl(因为 groovy 与 java 交互良好),允许非技术用户轻松编写脚本
  3. 创建一个 java 程序,它将评估 groovy 脚本并生成关联的 android 代码源(与 lib(来自(1))作为 gradle 依赖项)。
  4. 运行gradle androidTestCompile

由于函数在一个库中,开发人员可以轻松地将其包含在他们的项目中并使用它。因此所有用户都可以使用相同的库。

我讨厌这个想法,因为我必须从我的代码中生成代码源,但这是我唯一的。

问题

  • 这种方法是否像我认为的那样可怕?
  • 你知道另一种方法吗?

最佳答案

我会查看 https://cucumber.io/docs/reference/jvm#java ,它是一个库,通过让您将正则表达式与 Java 测试方法关联起来,几乎可以完全满足您的需求。

您的 Java 代码将类似于:

@When("^I open the app from the (main|home) screen$")
public void openApp(String launchScreen) {
...
}

测试文件看起来像:

Feature: Launching app

Scenario: Launching from first screen
When I open the app from the main screen
Then I see a blue icon...

Scenario: Launching from second screen
When I open the app from the second screen
Then I see a green icon...

关于java - 如何从 dsl 生成 UI 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34130835/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com