简体   繁体   English

Selenium-模拟数据库的自动化测试

[英]Selenium - Automation Testing Mocking a DB

I'm using spec-flow and selenium to do some automation testing. 我正在使用规格流程和硒进行一些自动化测试。

I'm testing a hierarchy component which may contain parent / child nodes. 我正在测试可能包含父/子节点的层次结构组件。

My test is to ensure that the hierarchy displays parent and child nodes but of course in the real system this will depend on the database being present and populated with the correct data is there a way to mock the database in automated test is it bad idea? 我的测试是确保层次结构显示父节点和子节点,但是当然,在实际系统中,这将取决于存在的数据库并填充正确的数据。有没有办法在自动测试中模拟数据库,这是一个坏主意吗?

How do I ensure that my tests are robust? 如何确保我的测试稳定可靠?

This feels like it's the wrong thing to do but given my problem I can't see any other alternatives but to ensure that my environment is always reset before each automation test run. 感觉这是错误的事情,但是鉴于我的问题,我看不到其他任何选择,但要确保在每次自动化测试运行之前始终重置我的环境。

As I understand from the details you provided, there's a component that is in charge of receiving data and displaying it as nodes (which is the component you want to test) and another component in charge of connecting to the database and getting the data. 从提供的详细信息中可以了解到,有一个组件负责接收数据并将其显示为节点(这是您要测试的组件),另一个组件负责连接数据库并获取数据。

In order to test the displaying component, it's perfectly valid (and possible - see some tutorials based on your programming language) to mock the DB component and it will even make your test more robust as there are fewer reasons for failures that are not related to the test (DB down etc...). 为了测试显示组件,模拟数据库组件是完全有效的(并且有可能-参见一些基于您的编程语言的教程),它甚至可以使您的测试更加可靠,因为与失败无关的失败原因更少测试(关闭数据库等)。

Basically, mocking should be used to make your tests test one thing and fake dependencies, so your case fits. 基本上,应该使用模拟来使您的测试测试一件事和伪造的依赖项,因此您的案例适合。

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

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