集成测试详细
我有一个 WCF 服务,可以访问数据库并向其中添加数据。 现在,我想做一些集成和/或系统测试(自动化)。
我该怎么做?
我必须访问数据库,加载初始数据,调用服务,然后验证预期的数据是否实际加载到表中。
您有什么推荐的策略吗?
我正在使用 WCF、实体框架、SQL Server、MSTests。
I have a WCF service that accesses the database and adds data to it.
now, I want to do some integration and/or system tests (automated).
How do I do it ?
I have to access the database, load initial data, call the service and then verify whether the data expected was actually loaded in the table.
is there any strategy for doing that you would recommend ?
I'm using WCF, Entity Framework, SQL Server, MSTests.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不介意您的测试项目依赖于实体框架,那么我将如何解决这个问题。
您还应该考虑使用轻量级的基于文件/内存数据库(例如 SQLite)来完成此任务。实现此目的的一种简单方法是使用 EF 从数据库生成模型,然后使用“从模型更新数据库”工具生成 SQL,该 SQL 将在 SQLite 实例中创建适当的表和约束。这意味着不会有修改主/开发数据库中数据的风险,并且可能会加快测试速度。
另外,关于步骤 3 和 6,有些人会提倡使用 MSTest 内置的设置/清理/拆卸功能可供性。在我看到它们有助于减少代码重复之前,我通常不会开始使用它们,因为在我看来,它们使测试不太清晰和可读,但这是个人的事情。
If you don't mind your test project taking a dependency on Entity Framework then here's how I would approach this.
You should also consider using a lightweight file-based/in-memory database such as SQLite for this task. One simple way of achieving this would be to use EF to generate a model from your DB, then use the Update Database From Model tool to generate the SQL that will create the appropriate tables and constraints in your SQLite instance. This means no risk of munting the data in your main/dev DB and potentially faster tests.
Also regarding steps 3 and 6, some people would advocate using the setup/clean-up/tear-down affordance built in to MSTest. I generally don't start using these until I can see them helping with reducing code duplication, because in my opinion they make tests less clear and readable, but that's a personal thing.