用testing数据库testingStrongloop RESTapi

我正在使用Strongloop开发Web应用程序,该应用程序将在Bluemix(云平台服务)上运行。

我的问题是,当我testing我想testing运行对另一个数据库,而不是内存数据库。

我有两个问题关于如何做到这一点:

  1. 是/我该如何configuration一个特定的数据库应该在运行testing时使用? 作为部署的一部分,我希望能够在Bluemix上部署时运行testing。 所以,如果我没有错,这是不够的,如果我可以手动使用一些参数设置什么数据库将运行时,我正在做一个“节点”。

  2. 另外在我的server.js我这样做我的数据库同步我的datamodel:

    var appModels = ['User']; var ds = app.dataSources.eventSeedElephantSQLDb; ds.isActual(appModels, function(err, actual) { if (!actual) { ds.autoupdate(appModels, function(err) { if (err) throw (err); }); } }); 

当我正在运行testing,我想运行类似的东西,而是我想迁移。

在testing中,我使用摩卡,柴和柴哈特。

您可以为testing创build一个“环境特定的configuration”。 请看: https : //docs.strongloop.com/display/public/LB/Environment-specific+configuration

例如,您可以创build另一个datasources.jsonconfiguration文件,但名称为datasources.test.json

 { "my-test-database": { "host": "localhost", "port": 27017, "database": "my-test-database", "connector": "mongodb" } } 

在testing的第一行,你定义了环境

 process.env.NODE_ENV = 'test'; //here I clean and create the data that I need, but you can use your database data beforeEach(function(done) { app.models['City'].destroyAll(); app.models['City'].create({name: 'city test', country: 'Brazil'}); }); describe('/city', function() { it('should find a city', function(done) { request(app).get('/api/city').expect(200); }); });