Tag: unit testing

有没有办法通过maven / ant运行nodeunittesting

我为nodeunit中的node.js应用程序创build了一些unit testing。 我希望能够通过maven / ant来运行testing,因为我打算通过Jenkins运行它们。 有没有人有这样做的成功?

我怎样才能让我的node.jsunit testing识别node_modules?

我有以下代码: var foo = require('foo'); /* module.exports = function(n){ return 2 * n} */ describe('basic', function(){ describe('body', function(done){ foo(2).should.equal(4); }); }); 这是在[project_root]/tests/foo_test.js 。 foo.js位于[project_root]/node_modules/foo.js 。 但是,当我从[project_root]运行mocha (visionmedia的testing套件) foo_test.js无法加载foo.js proces.cwd()显示[project]作为进程的根。 为什么不在我的testing环境中加载foo.js ?

在node.js中对unit testing中的依赖关系进行存根

我从node.jsunit testing开始,并且一直在研究node.js中最常用的unit testing框架。 我想从最常用的框架开始,使事情变得简单,因为可能有更多的信息。 据许多网站可能是摩卡。 虽然我理解这个模块来进行集成testing,但我并不知道如何使用诸如存根依赖之类的特性来处理它。 我已经看到摩卡不提供模拟/存根function,所以我不知道人们通常如何处理这些问题。 所以我想知道现在最stream行的unit testing模块是什么模块,依存关系……一个简短的例子会很棒。 谢谢

如何使用gruntJS运行testing

那么,如何在gruntjs中运行testing套件呢? 我认为这应该是非常简单而直接,但对我来说,它不是:) 由于gruntjs应该能够运行testing,我认为我可以运行“grunttesting”,但由于某种原因需要服务器运行。 我试着用“grunt server watch”在另一个进程中启动它,但是再次“grunttesting”失败。 咕噜声应该如何工作?

Node.js上Geddy MVC的unit testing框架

我正在Heroku上的Node.js上运行Geddy MVC框架,并使用Postgres数据库。 我似乎无法find任何支持Geddy的node.js的unit testing框架。 我试过nodeunit,茉莉花和其他一些,但似乎没有与geddy(说它是未定义的 – 我想是因为它不知道如何导入所有必需的文件)。 我知道Geddy提供了他们的杰克testing工具,但它似乎也不工作。 它给了我这个输出: ReferenceError: geddy is not defined 任何帮助将不胜感激。 也在寻找一个代码覆盖的工具,将与我开始工作的unit testing框架一起工作。 谢谢! 编辑:我的testing都开始这个头来导入所需的模块: var assert = require('assert') , tests , Activity = geddy.model.Activity; 而Activity的导入失败,上面的ReferenceError,所以它甚至从来没有尝试我的testing。 这是我写的一个nodeunittesting var tests , User = geddy.model.User; exports['addUser1'] = function (test) { var user = User.create({username: 'Greg', password: 'MyPassword!', confirmPassword: 'MyPassword!', familyName: 'LastName1', givenName: 'FirstName1', […]

如何testing自己的MongoDB包装

我已经编写了自己的用于Node.js的瘦蒙哥包装,以消除代码重复。 但是,我在使用Mocha和Should运行asynchronousunit testing时遇到问题。 会发生什么情况是,由MongoDB驱动程序而不是Mocha捕获的应用程序库引发的任何exception。 也就是说,Mocha既不会捕获错误,也不会调用done()函数。 因此,摩卡打印出一个错误Error: timeout of 2000ms exceeded 。 包装模块db.js片段 var mongodb = require('mongodb').MongoClient; exports.getCollection = function(name, callback) { mongodb.connect(dbConfig.dbURI, {auto_reconnect: true}, function(err, db) { if (err) return callback(err, null); db.collection(name, {strict: true}, callback); }); }; 摩卡test.js var should = require('should'); var db = require('./db.js'); describe('Collections', function() { it.only('should retrieve user collection', function(done) […]

unit testingnode.js模型代码访问MongoDB,而不实际访问数据库

例如,我有下面的代码: var db = require('./_mongo.js'); module.exports = { check: function (cb) { var content = {}; content.collection = 'counters'; content.query = {_id: 'ping'}; content.columns = {}; db.read(content, function(err, result){ if (err) { cb(-1); } else { cb(0); } }); } }; 如何在不实际访问数据库的情况下编写“check”函数的unit testing,同时检查是否能够编写正确的传递给读取方法的“content”variables?

before()在之后的describe()之前不执行?

给出以下代码: var api = {}; var models = {}; describe(vars.project.name, function() { before(function(done) { // Loading models models_module.getDbInstance('0.1', function(res) { db = res; var config = { server: server, db: db, v: '0.1' }; // Importing all the tests api.base = require('./functions/api.base.js')(config); models.test_table = require('./functions/models.test_table.js')(config); done(); }); }); // Tests general status describe('checking the status […]

摩卡asynchronoustesting,重用相同的请求

我正在testing一个HTTP服务器。 我希望我可以通过describe() ,而不是仅仅it() ,如下所示: var request = require('supertest'); describe('Item', function(done){ request(app).get('/').end(function(req, res){ it('should have one thing', function(){ // Assert on res.body }); it('should have another thing', function(){ // Assert on res.body }); it('should have more things', function(){ // Assert on res.body }); done(); }); }); 这是行不通的,摩卡从不运行testing。 下面的代码可以工作,但是每次创build一个新的HTTP请求时,我都希望使用相同的代码。 describe('Item', function(){ it('should have one thing', function(done){ request(app).get('/').end(function(req, […]

Geddyunit testing控制器

你如何testinggeddy控制器? 这是我想testing的一个例子。 var assert = require('assert') , tests , controller = geddy.controller.create('Users'); tests = { 'test user controller, add new user': function (next) { var user = User.create({username: 'hbinduni', password: 'MyPassword!', confirmPassword: 'MyPassword!', familyName: 'binduni', givenName: 'binduni', email: 'hbinduni@email.com'}); //need to unit test controller.add here //how to mock req, resp? controller.add(req, resp, user); assert.equal(out, null); […]