我的问题是这一个的变种.
由于我的Java Web应用程序项目需要大量读取过滤器/查询以及与GridFS等工具的接口,因此我很难想到以上述解决方案建议的方式使用MongoDB的合理方法.
因此,我正在考虑在我的集成测试中运行MongoDB的嵌入式实例.我希望它能自动启动(对于每个测试或整个套件),为每个测试刷新数据库,最后关闭.这些测试可能在开发机器和CI服务器上运行,因此我的解决方案也需要是可移植的.
任何对MongoDB有更多了解的人都能帮助我了解这种方法的可行性,并且/或者建议任何可能帮助我入门的阅读材料吗?
我也对人们对如何处理这个问题的其他建议持开放态度......
我正在尝试编写测试来测试连接到mongo的方法,但我实际上并不想让mongo运行并实际建立连接以使我的测试成功通过.
这是我当前的测试,当我的mongo守护程序运行时,它是成功的.
describe('with a valid mongo string parameter', function() {
it('should return a rejected promise', function(done) {
var con = mongoFactory.getConnection('mongodb://localhost:27017');
expect(con).to.be.fulfilled;
done();
});
});
Run Code Online (Sandbox Code Playgroud)
mongoFactory.getConnection代码:
getConnection: function getConnection(connectionString) {
// do stuff here
// Initialize connection once
MongoClient.connect(connectionString, function(err, database) {
if (err) {
def.reject(err);
}
def.resolve(database);
});
return def.promise;
}
Run Code Online (Sandbox Code Playgroud)