1
1
---
2
- title : " Domain specific language "
2
+ title : " 领域特定语言 "
3
3
weight : 2
4
4
---
5
5
6
- {{% notice info %}}
7
- <i class =" fas fa-language " ></i > 页面需要从英语翻译为简体中文。
8
- 您熟悉英语与简体中文吗?帮助我们翻译它,通过 pull requests 给我们!
9
- {{% /notice %}}
10
6
11
- A domain specific language (DSL) is a system which provides the user with
12
- an expressive means of solving a problem. It allows a user to
13
- interact with the system on their terms – not just programmer-speak.
7
+ 领域特定语言 (DSL) 是一种为用户提供解决问题的表达方式的系统.
8
+ 它使用户可以按照自己的术语与系统进行交互, 而不仅仅是通过程序员的语言.
14
9
15
- Your users, in general, do not care how your site looks. They do not
16
- care about the decoration, animations, or graphics. They
17
- want to use your system to push their new employees through the
18
- process with minimal difficulty; they want to book travel to Alaska;
19
- they want to configure and buy unicorns at a discount. Your job as
20
- tester is to come as close as you can to “capturing” this mind-set.
21
- With that in mind, we set about “modeling” the application you are
22
- working on, such that the test scripts (the user's only pre-release
23
- proxy) “speak” for, and represent the user.
10
+ 您的用户通常并不关心您网站的外观.
11
+ 他们不在乎装饰, 动画或图形.
12
+ 他们希望借助于您的系统, 以最小的难度使新员工融入整个流程;
13
+ 他们想预订去阿拉斯加的旅行;
14
+ 他们想以折扣价配置和购买独角兽.
15
+ 您作为测试人员的工作应尽可能接近"捕捉”这种思维定势.
16
+ 考虑到这一点, 我们开始着手"建模”您正在工作的应用程序,
17
+ 以使测试脚本 (发布前用户仅有的代理) "说话”并代表用户.
24
18
25
- With Selenium, DSL is usually represented by methods, written to make
26
- the API simple and readable – they enable a report between the
27
- developers and the stakeholders (users, product owners, business
28
- intelligence specialists, etc.).
29
19
30
- ## Benefits
20
+ 在Selenium中, DSL通常由方法表示,
21
+ 其编写方式使API简单易读-它们使开发人员和干系人
22
+ (用户, 产品负责人, 商业智能专家等) 之间能够产生汇报.
23
+
24
+
25
+ ## 好处
31
26
32
- * ** Readable:** Business stakeholders can understand it.
33
- * ** Writable:** Easy to write, avoids unnecessary duplication.
34
- * ** Extensible:** Functionality can (reasonably) be added
35
- without breaking contracts and existing functionality.
36
- * ** Maintainable:** By leaving the implementation details out of test
37
- cases, you are well-insulated against changes to the AUT* .
27
+ * ** 可读:** 业务关系人可以理解.
28
+ * ** 可写:** 易于编写, 避免不必要的重复.
29
+ * ** 可扩展:** 可以 (合理地) 添加功能而无需打破约定以及现有功能.
30
+ * ** 可维护:** 通过将实现细节排除在测试用例之外, 您可以很好地隔离 AUT* 的修改.
38
31
39
32
40
33
## Java
41
34
42
- Here is an example of a reasonable DSL method in Java.
43
- For brevity's sake, it assumes the ` driver ` object is pre-defined
44
- and available to the method.
35
+ 以下是Java中合理的DSL方法的示例.
36
+ 为简便起见, 假定 ` driver ` 对象是预定义的并且可用于该方法.
45
37
46
38
``` java
47
39
/**
@@ -68,11 +60,10 @@ public AccountPage loginAsUser(String username, String password) {
68
60
}
69
61
```
70
62
71
- This method completely abstracts the concepts of input fields,
72
- buttons, clicking, and even pages from your test code. Using this
73
- approach, all a tester has to do is call this method. This gives
74
- you a maintenance advantage: if the login fields ever changed, you
75
- would only ever have to change this method - not your tests.
63
+ 此方法完全从测试代码中抽象出输入字段, 按钮, 单击甚至页面的概念.
64
+ 使用这种方法, 测试人员要做的就是调用此方法.
65
+ 这给您带来了维护方面的优势: 如果登录字段曾经更改过,
66
+ 则只需更改此方法-而非您的测试.
76
67
77
68
``` java
78
69
public void loginTest() {
@@ -89,14 +80,12 @@ public void loginTest() {
89
80
}
90
81
```
91
82
92
- It bears repeating: one of your primary goals should be writing an
93
- API that allows your tests to address ** the problem at hand, and NOT
94
- the problem of the UI** . The UI is a secondary concern for your
95
- users – they do not care about the UI, they just want to get their job
96
- done. Your test scripts should read like a laundry list of things
97
- the user wants to DO, and the things they want to KNOW. The tests
98
- should not concern themselves with HOW the UI requires you to go
99
- about it.
100
83
101
- *** AUT** : Application under test
84
+ 郑重强调: 您的主要目标之一应该是编写一个API,
85
+ 该API允许您的测试解决 ** 当前的问题, 而不是UI的问题** .
86
+ 用户界面是用户的次要问题–用户并不关心用户界面, 他们只是想完成工作.
87
+ 您的测试脚本应该像用户希望做的事情以及他们想知道的事情的完整清单那样易于阅读.
88
+ 测试不应该考虑UI如何要求您去做.
89
+
90
+ *** AUT** : 待测系统
102
91
0 commit comments