简体   繁体   English

编码的UI测试

[英]Coded UI Testing

I want to automate some testing using coded ui testing. 我想使用编码的ui测试来自动化一些测试。 Some of my tests involve making transactions against a database that I want to assert things from. 我的一些测试涉及对要声明其内容的数据库进行事务处理。 But running these automated tests introduce their own issues, everytime the test runs it could be modifying (adding, updating, or removing records) the state of my database. 但是运行这些自动化测试会带来他们自己的问题,每次运行测试时,它都可能会修改(添加,更新或删除记录)我的数据库状态。 Is there some general guidance how to create coded ui tests when modifying a database? 是否有一些一般性指导,说明在修改数据库时如何创建编码的ui测试? Do I want to add mock repositories? 我是否要添加模拟存储库? Do I want to create a test environment that has a database server that can be reverted to snapshot with each test run? 我是否要创建一个测试环境,该环境的数据库服务器可以在每次测试运行时恢复为快照? Should coded ui testing not involve asserting values from a database transaction and instead just assert a button was clicked and have unit testing assert the database transactions? 编码的ui测试是否应该不涉及声明数据库事务中的值,而只声明一个按钮被单击并且单元测试是否声明数据库事务?

IMHO this question applies to any test you write - not only specifically to CodedUI tests. 恕我直言,这个问题适用于您编写的任何测试-不仅限于CodedUI测试。

Your tests could Query/ExecuteNonQuery on a db as they progress. 随着测试的进行,您的测试可以在db上查询/ ExecuteNonQuery。 So the DB would move from state A to state B by the end of the test run. 因此,数据库将在测试运行结束时从状态A移至状态B。 Therefore its good to make sure that you have some DB refresh scripts run at the start of the test run so you can make sure that you brought the db into State A before the run irrespective its current state. 因此,最好在测试运行开始时确保有一些数据库刷新脚本运行,这样就可以确保在运行前将数据库带入状态A,而不管其当前状态如何。

Its probably good to note that when you run the same tests on the same test data with the DB state remaining the same at the start of the test run, you are performing the exact same test each time and the chances are the application under test has become immune to those tests and the test run ends up with diminishing returns over time. 可能需要注意的是,当您在相同的测试数据上运行相同的测试,并且在测试运行开始时数据库状态保持不变时,您每次都执行完全相同的测试,并且被测应用程序有可能拥有变得不受这些测试的影响,并且随着时间的流逝,测试运行最终会减少收益。 So its probably a good idea to randomize the test data on which the tests work. 因此,随机化测试所依据的测试数据可能是一个好主意。

It can be as simple or as complicated as you want it. 它可以根据需要简单或复杂。

Simplest approach is to completely reset the data with each run. 最简单的方法是在每次运行时完全重置数据。 This might mean creating the db from scratch each time using some schema creation script. 这可能意味着每次使用某些架构创建脚本从头开始创建数据库。

A more complicated solution would be to only reset parts of the schema (ie: certain tables, depending on the nature of the test). 一个更复杂的解决方案是仅重置架构的某些部分(即:某些表,具体取决于测试的性质)。 Related tables, etc. 相关表格等

Whatever you do - it's bad practice to expect the tests to run in a certain order. 无论您做什么-期望测试按特定顺序运行都是不好的做法。 If you have 50 tests as part of your suite, these tests must be capable of running in any order, and run according to the tester - who might decide to run 1 or all of your tests. 如果您有50个测试作为套件的一部分,则这些测试必须能够按任何顺序运行,并且必须根据测试人员运行-测试人员可能决定运行1个或全部测试。

That's the high level stuff. 那是高级的东西。 In terms of actual implementation, you can find interesting ways to mark tests with attributes and there you can define values of what you will initialize (this could be table names to clear, or if you're working with an ORM could be 1 entity, and from there dynamically determine related tables. And run clean outs dynamically. 在实际实施方面,您可以找到有趣的方法来标记带有属性的测试,并在那里定义要初始化的值(可以是要清除的表名,或者如果要使用ORM可以是1个实体,然后从那里动态确定相关表,并动态运行清除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM