2014-01-16 4 views
0

나는 Nodejs + Mongoose + MongoDB 웹 애플리케이션을 구축하고 있으며, 재스민 유닛 테스트 프레임 워크로 DAO 메소드를 단위 테스트하려고합니다. 나는이 같은 함수를 호출 내 컨트롤러에 다음 코드몽구스 Jasminejs 유닛 테스트 crud methods (DAO)

/** 
* List of Profiles 
*/ 
    exports.all = function(req, res) { 
    Profil.find().exec(function(err, profils) { 
    if (err) { 
     res.render('error', { 
      status: 500 
     }); 
    } else { 
     // console.log(profils._id); 
     res.jsonp(profils); 
    } 
}); 
}; 

에게이 모든 프로파일을 표시 할 책임이 내 DAO 기능에

var mongoose = require('mongoose'); 

var Schema = mongoose.Schema; 

var profilSchema = new Schema({ 
photo: {type: String}, 
nom: {type: String , required: true}, 
type: { type: String , required: true}, 
descriptif: {type: String, required: true}, 
niveauScolaire: {type: String , required: true}, 

}); 

/** 
* Statics 
*/ 
profilSchema.statics = { 
load: function(id, cb) { 
    this.findOne({ 
     _id: id 
    }).exec(cb); 
} 
    }; 

    var Profil = mongoose.model('Profil', profilSchema); 

:

내 모델은 다음과 같다 :

$scope.afficherProfils = function() { 
    $http.get('/listerProfil') 
     .success(function(data) { 
     $scope.listeProfils = data; 

    }); 

}; 

어떻게 이런 종류의 기능을 테스트 할 수 있습니까? 일부 요소를 mongoDB 데이터베이스에 삽입하고 함수가 정보를 얻는 지 테스트 할 수 있습니까? 이런 종류의 단위 테스트에는 이전 경험이 없습니다.

답변

1

서버 측 기능과 클라이언트 측 기능을 별도로 테스트해야합니다.

Angularjs 비트가 브라우저에서 실행됩니다. karma 또는 testem을 사용하여 클라이언트 측 테스트를 실행할 수 있습니다. 테스트에서 실제 http 요청을 할 필요가 없습니다. 동작을 제어하려면 $httpBackend 수 있습니다.

AngularJS와

추가 읽기 자료에 대한 서면 단위 및 E2E 테스트의 더 나은 이해를 얻기 위해 AngularJS와 문서에 자스민 테스트 및 다이빙을 작성하는 방법에 대해 살펴 보자

http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-karma.html http://www.yearofmoo.com/2013/09/advanced-testing-and-debugging-in-angularjs.html

node.js 비트가 서버 측에서 실행될 예정이면 mocha을 사용하여 서버 측 테스트를 실행할 수 있습니다. 많은 프로젝트는 테스트를 위해 별도의 테스트 데이터베이스를 사용하며, 테스트 슈트가 실행되기 전에 테스트 데이터로 채워진 다음 테스트 실행이 완료되면 데이터베이스를 정리합니다.

+0

많은 도움을 주신 덕분에 – badaboum