简体   繁体   English

在Node.js测试之后清理数据库

[英]Cleaning database after Node.js test

Previously, I used Django (Python). 以前,我使用Django(Python)。 In tests creating new lines in database, but after tests new lines automatically delete. 在测试中,在数据库中创建新行,但在测试后,新行会自动删除。 Is there a Node.js test framework that automatially clean test line and tables? 是否有一个Node.js测试框架可以自动清理测试行和表格?

You could look into using something like mochajs . 您可以考虑使用类似mochajs东西。 Mocha exposes several hooks to aid build up and teardown for tests. 摩卡(Mocha)暴露了多个挂钩,以帮助建立和拆除测试。 There are many testing frameworks but, I've found mocha to be one of the best, especially when coupled with assertion libraries like chaijs 有很多测试框架,但是我发现mocha是最好的框架之一,尤其是当与chaijs断言库结合使用时

Your tests could then be structured similar to the following: 然后,您的测试的结构类似于以下内容:

describe('My Database Test', function() {
  before(function() {
    // create test table or test records
  });

  after(function() {
    // delete test table or remove test records
  });

  it('should insert new records', function() {
    // insert some test rows
  })
});

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

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