如何使用测试数据库进行实习测试

时间:2016-02-05 03:42:55

标签: intern

我在我的节点项目中使用实习生进行测试,但是我不知道如何正确设置实习生,以便它使用'test'数据库而不是'development'数据库。我试图将代码process.env.NODE_ENV = 'test'放入我的测试文件中,但它不起作用。我的intern.js文件只是默认文件,我的实习运行命令是/node_modules/.bin/intern-client config=tests/intern。除了在开发数据库而不是测试数据库中生成数据之外,所有测试都正常运行。任何人都知道如何解决它?谢谢!

这是我的测试套件中的一个测试用例,它将数据添加到数据库

tdd.test('normal user creation', function(){
  var name = chance.name();
  return models.User.create({
    name: name,
    gender: chance.gender(),
    email: chance.email(),
    balance: 0.0,
    phone_number: chance.phone({country: 'ca', mobile: true})
  }).then(function (user) {
    return assert.strictEqual(name, user.name, 'user name should ' +
      'be equal to each other');
  }).catch(function (error) {
    throw new Error(error.message);
  });
});

1 个答案:

答案 0 :(得分:0)

最后,我找到了解决方案。在package.json文件中,将scripts选项设置为

"scripts": {
  "start": "node src/index.js",
  "test": "set NODE_ENV=test&&intern-client config=tests/intern"
},

然后运行npm test,实习生将立即在测试数据库上运行测试基础

相关问题