测试初始化​​-在运行测试之前做一些事情 [英] Testing initialize - do something before run tests

查看:138
本文介绍了测试初始化​​-在运行测试之前做一些事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我想知道是否有可能在运行测试之前在DB中创建测试记录.我知道有ClassInitialize()和TestInitialize(),但是它们在每个类和测试中都能正常工作.我有很多课,需要简单的用户记录 在分贝.我不想在每个类正在初始化时创建记录int db.

I'm wondering if there is possibility to create a testing record in DB before running tests. I know that there is ClassInitialize() and TestInitialize() but those work fine in each class and test. I have many classes which requires a simple record of user in db. I don't want to create record int db each class is initializing.

我有想法,要创建具有最高优先级的测试方法.在该测试中,将某些东西放入数据库中,进行大约30秒的睡眠测试并清理数据库.

I have idea, to create a testmethod with highest priority. In this test put something in database, sleep test for about ~30seconds and clean-up database.

任何想法都会很有帮助.

Any ideas will be very helpful.

我使用vs 2010pro

I use vs 2010pro

推荐答案

当然,您可以做一个单独的测试,就是在进行此初始化.但这是我不推荐的,因为每个测试都可以正常运行,而不必依赖于其他测试.

of course you can do a seperate test taht is doing this initialisation. But that is something that I would not recommend, because each test should run fine without a dependency to other tests.

因此,至少我们可以确保每个测试都有适当的初始化和清理(如果需要),以便每个测试可以独立运行.如果只有一个初始化,您应该想到:

So at least we make sure, that each test has a propper initialisation and cleanup (if required) so each test can be run independently. If you have just one initialisation, you should think of:

-将代码移至单独的类(因此您不必重复代码)
-如果已经完成初始化,则可能要进行适当的测试(取决于初始化,这可能会加快速度.但是,如果您希望随后再进行清理,则可能会不必要).

- moving the code to a seperate class (So you do not have to repeat the code)
- Maybe have a propper test, if the initialisation was done already (Depending on the initialisation, this could speed up things. But if you want to clean up afterwards again, it could be unwanted).

这就是我们在团队中如何做这些事情.我希望这对您有所帮助,也许其他人有更好的主意.

This is just, how we do this stuff in our team. I hope it was of some help for you and maybe someone else has much better ideas.

以诚挚的问候,

Konrad


这篇关于测试初始化​​-在运行测试之前做一些事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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