构建e2e测试的一些最佳做法是什么? [英] What are some best practices for structuring e2e tests?

查看:132
本文介绍了构建e2e测试的一些最佳做法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于构建端到端测试的最佳方法我有些困惑.

I'm a bit confused as to the best way to structure end to end tests.

我编写的大多数测试都依赖于其他测试.

Most tests tests that I write depend on other tests.

  • 用户需要登录
  • 用户需要创建Foo
  • 用户现在可以创建栏
  • 酒吧必须存在,以便对其进行明显的编辑.

您将如何构造测试以考虑到这一点?

How would you structure your tests to take this into account?

推荐答案

我个人将使用PageObject模式,这将提高可靠性,并使代码在这些情况下更具可维护性. 一旦有了适当的位置,就可以在对那些页面起作用的PageObject类中创建不同的方法. 例如.

I would personally make use of the PageObject pattern, this will allow reliability and make the code more maintainable in these situations. Once you have that in place you can then create different methods in your PageObject classes that act upon those pages. E.g.

LoginPage将是使用PageObject模式的类,并且包含类似LogIn()的方法,该方法将返回HomePage的类型,而该类型将是使用PageObject模式的另一个类.

LoginPage would be a class using the PageObject pattern and would contain methods like LogIn() which would return the type of HomePage, which would be another class using the PageObject pattern.

我没有使用Selenium在应用程序上进行E2E测试,因为我认为该工具不是为此目的而设计的.

I have not used Selenium to preform E2E tests on an application since I don't think the tool is designed for that.

您真正想要的是一种执行BDD的工具(行为驱动的开发).

Really what you want is a tool to preform BDD (Behaviour Driven Development).

我构建帖子中场景的方式是,我将对每个场景进行单独的测试.我要进行一次测试,以确保我可以成功和失败地登录.然后,我将进行另一个测试,该测试将创建一个用户"Foo",然后将一个静态"用户准备好进行编辑.

The way I would structure your scenario that is in your post is that I would have separate tests for each one. I'd have a Test to make sure I can log in successfully and unsuccessfully. I would then have another test that would create a user 'Foo', then would have a 'static' user ready to edit.

这篇关于构建e2e测试的一些最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆