English 中文(简体)
设计做法:在删除试验案件之前制定守则?
原标题:Design Practice: code to create before deletion in deletion test case?

I have written test case for deletion of entity. In test case I simply pick first record by select query and pass its id to deletion method. Entity I want to delete can have some child entities restricting it from deletion. So I suppose I should create a entity first in my deletion test case and destroy same then so that I don t face issues of child dependency. Is it good practice to write code for creation of entity before deletion. Its kind of testing creation method before deletion method.Please suggest

Edit: I am working on Rail platform, so I have features like loading database with fixtures (not using currently, facing some error with same, see this https://stackoverflow.com/questions/5288142/rails-fixture-expects-table-name-to-be-prefixed-with-module-name-how-to-disable ). And yes I am using configuration to restore database state after test case run.

问题回答

In unit-testing, you usually perform some sort of set-up before you run your tests.

许多测试框架支持这种运作。 通常,你不通过外部询问这样做;例如,你可以直接制造带有某些特性的物体,而不是进行外部衍生的<代码>create查询。

Because you directly create the object in the first place, you are not testing your creation query code (unless the way you internally create objects is flawed, but if you are concerned about that, you can test it too), and your deletion code is the only thing being tested.

In test case i simply pick first record by select query

这是错误的。 在单位测试期间,你不应进行询问。

我看到的检验可以:

  1. Delete an existent;
  2. Delete a non existent Entity;
  3. Delete a child;
  4. Delete a non existent child;

如果你的单位测试框架允许测试依赖性,即只有在测试Y通行证和将Y的回报值作为参数通过X时,你才能放弃测试。 这里如何看待购买力平价:

function setUp() {
    $this->dao = new UserDao(...);
}

function testCreate() {
    $user = $this->dao->create( Bob );
    assertThat($user, notNullValue());
    // more assertions about the new user
    return $user->getId();
}

/**
 * @depends testCreate
 */
function testDelete($id) {
    assertThat($this->dao->delete($id), is(true));
}

如果测试失败,PHPUnit将进行超时测试。 如果你不能在每次试验之前建立标准测试数据,那么这是一个良好的工作环绕。

在删除前起草实体创建守则是否良好做法。 在删除方法之前采用这种测试生成方法。 请建议

是的,建立删除你正在测试的实体是一种良好做法,以便测试不取决于外部情况,并且可以重复,独立于其他测试。

为确定删除标准,本文件仅作少量印发。

如果你根据相同数据进行了多次测试,则可以将制作工作引向一种方法,在每次测试中,你都需要这一数据。 多数测试框架还有一个具体规定<代码> > >> >> >的机制。 在每次测试之前使用的方法,如果需要所有测试类别的数据,则你可以把制造放在试验场。





相关问题
Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Best browser for testing under Safari Mobile on Linux?

I have an iPhone web app I m producing on a Linux machine. What s the best browser I can use to most closely mimic the feature-limited version of Safari present on the iPhone? (It s a "slimmed down" ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Is there any error checking web app cralwers out there?

Wondering if there was some sort of crawler we could use to test and re-test everything when changes are made to the web app so we know some new change didn t error out any existing pages. Or maybe a ...

热门标签