如何使用测试数据库进行实习测试
How can I use test database for intern testing
我在我的节点项目中使用 intern 进行测试,但是我不知道如何正确设置 intern 以便它使用 'test' 数据库而不是 'development' 数据库。我试图将代码 process.env.NODE_ENV = 'test'
放入我的测试文件中,但它不起作用。我的 intern.js
文件只是默认文件,我的实习生 运行ning 命令是 /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);
});
});
终于,我找到了解决办法。在 package.json
文件中,将 scripts
选项设置为
"scripts": {
"start": "node src/index.js",
"test": "set NODE_ENV=test&&intern-client config=tests/intern"
},
然后运行npm test
,实习生现在运行测试数据库上的测试库
我在我的节点项目中使用 intern 进行测试,但是我不知道如何正确设置 intern 以便它使用 'test' 数据库而不是 'development' 数据库。我试图将代码 process.env.NODE_ENV = 'test'
放入我的测试文件中,但它不起作用。我的 intern.js
文件只是默认文件,我的实习生 运行ning 命令是 /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);
});
});
终于,我找到了解决办法。在 package.json
文件中,将 scripts
选项设置为
"scripts": {
"start": "node src/index.js",
"test": "set NODE_ENV=test&&intern-client config=tests/intern"
},
然后运行npm test
,实习生现在运行测试数据库上的测试库