处理许多需要在运行断言之前导航到特定位置的测试用例的最佳方法?例如一个流程有5个步骤,一个测试用例需要测试第5步的一部分,我该如何设置?在这个测试用例中调用前面步骤的测试用例方法,并对所有测试步骤 5 的测试用例执行此操作?
同样,如果测试用例深入网站 - 通过许多页面 - 是否应该为每个测试用例重写导航,还是只调用一些已经这样做的测试?
关于这种情况有什么提示吗?
最佳答案
Best way of handling many test cases needing to navigate to a particular place before they run their asserts? For example a process has 5 steps and a test case needs to test a part of step 5, how can I set it up?
我会创建一个 Transporter 类/模式,测试用例可以调用它来达到该状态。这将使导航代码可重用于其他测试,并且不会使测试太大/太复杂。您还可以在 xUnit 测试框架中使用 setUp()
方法,如果您需要将其用于其他测试,该方法将在每次测试之前调用并将导航器代码放在那里。
Similarly, if a test case goes deep into the website - through many pages - should that navigation be re-written for every test case, or just call some test that already does that?
我将该代码提取到一个名为 Transporter 的帮助程序类中,并让测试调用它以在一个方法调用中轻松导航到深层页面。
我在 conference paper 中写过这个和其他测试设计模式在太平洋西北地区软件质量 session 上。在 paper 中寻找转运蛋白模式.
这是一个使用 Transporter 类的示例,您必须在其中登录并导航到结帐页面:
public class Transporter {
public static void login() {
//App specific code to navigate to login screen and login to the application
}
public static void gotoCheckout() {
//App specific code to navigate to the checkout page
}
}
现在您的测试只需调用这个 Transporter 类来为它们导航。
关于unit-testing - 在进程中设置 "late"测试用例的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51878088/