0

我有一些与我的问题建模有关的问题。我正在从事基于模型的测试的论文项目。还想从专家的角度了解我是否采用正确的方法来建模我的场景。我正在为 android 应用程序的 UI 建模,遍历它们,生成测试用例并为 espresso 框架生成测试代码。

我将简单地解释我对被测系统进行建模并为测试用例生成测试代码的方式。(我也在编写生成android代码的算法)。我正在为 android espresso 测试框架生成代码。espresso 的结构总是需要首先找到与之交互的元素。这是通过将“OnView()”方法传入其中的参数来完成的,例如 withId(R.id.title) 或 withText(“Hello”) 以分别找到具有给定 Id 或 Text 的元素。然后,我们附加框架调用的 ViewActions 或 ViewMatchers 以分别通过执行操作或执行断言来与元素交互。下面是一个 espresso 测试用例的示例,它找到一个带有文本“幸运按钮”的文本视图,点击它并检查它是否显示。

@Test
public void test () {

  onView(withText(“Lucky Button”))      //ViewMatcher
       .perform(click())             // ViewAction  .check(matches(isDisplayed())); // ViewAssertion

简单案例 让我们以一个有两个屏幕的 android 应用程序为例。屏幕 A 和屏幕 B。每个屏幕包含不同的元素。例如 TextView(Textlabel)、ImageView(Image label) 等 我使用状态图来描述屏幕可以处于的状态。对于每个状态,都有一个活动图来描述要对元素执行的测试,例如 TextView、ImageView。我们将每个测试套件分组在泳道中,并用活动操作表示测试操作。但是有需要的输入信息。例如,可以调用活动操作 isVisible 来检查 ToolBarDesign 泳道中工具栏的可见性。为了达到这个动作,我们需要工具栏上的信息来首先定位它并检查它的可见性。我通过提供有关动作或状态转换的必要信息来做到这一点。

在此处输入图像描述

此状态图有 2 个状态。从 MainActivity 转换到 NewNote 是一个名为 openNewNote 的触发器,其动作是自由文本格式的。自由文本操作包含必要的信息,我通过这些信息在我的 java 框架中处理和提取,以生成类似于上述代码的一段代码。在框架中,我先选择id为title的元素,然后执行click方法。同样在 MainActivity 状态中包含一个如前所述的子活动图。在这个子活动图中,我们为人员建模(我们认为他是具有 espresso 框架知识的人)提供了编写活动操作以进行测试的机会。下面是一个测试应用程序工具栏和登录屏幕的 MainActivity 活动图示例。

在此处输入图像描述

工具栏从初始节点过渡到 isVisible 活动。关于转换,我们在状态图上对转换进行如上所述的描述。在这里,我们得到自由文本动作“withText:Lucky Button,matches,isDisplayed”,然后在我们的框架中对其进行处理以获取代码。

 @Test
public void test () {

  onView(withText(“Lucky Button”))      //ViewMatcher
        .check(matches(isDisplayed())); // ViewAssertion

问题。到目前为止,这对团队有效,因为程序员是建模的人。我将提供用于建模系统的文档。我想问一下这是否是一种有效的建模方式,是否可以在我的研究中描述。如果您有任何意见或建议。

4

1 回答 1

1

Without going into deep details, I would recommend going one step back and start broader:

  • Define more formally what the system under test (SUT) is in your case: inputs, ouputs, requirements correlating inputs and outputs. Examples would be a state machine, activity diagram etc.
  • Define more formally what you like to model: a parallel implementation to the SUT which is your test model (TM). It is usually abstracter and only valid in some limited area of the behaviour of the SUT. In your case the sequence and activity diagrams.
  • A conformance relation: What is the formal definition that SUT conforms to TM? How do these two models SUT and TM compare?
  • What is the theory which can formally and automatically prove the conformance relation? This gives also the answer to the tools needed for automation.

The best way to start is to exercise on examples:

  • Understand all demo examples from at least one of the big MBT-Tools: Microsoft Spec Explorer, Conformiq Designer ...
  • Model your example in one of them roughly.
  • See how they use UML. I recommend the UML extension of Spec Explorer to you which focuses on input data generation and scenarios and less on behaviour - similar to your application.
  • Understand the theory behind these tools: symbolic execution, alternating simulation, scenarios etc.

If you answer these questions you have also the answer if your approach is valid or has any errors, which I can't answer from what you presented.

于 2017-05-14T10:44:36.130 回答