Mocha-Chai测试:在Openshift上的Jenkins上运行两次POST测试

时间:2016-03-27 05:21:33

标签: jenkins openshift mocha mean chai

我的应用程序概述:

  1. 我在OpenShift上有一个MEAN Stack应用程序。
  2. 一系列测试是在Chai-Mocha框架中编写的,该框架在Jenkins上运行。
  3. 我有一个POST Api的测试用例,它在本地完美运行但在服务器上运行两次。
  4. 我正在使用Xunit为Jenkins生成测试报告。
  5. POST Api的单个测试执行两次,我得到一个错误,即构建失败,因为1次测试通过,1次失败。
  6. 以下是我的代码:

    Server.js

    'use strict';
    var express = require('express');
    var app = express();
    var path = require('path');
    var favicon = require('serve-favicon');
    var logger = require('morgan');
    var cookieParser = require('cookie-parser');
    var bodyParser = require('body-parser');
    var mongoose = require('mongoose');
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: false }));
    app.use(cookieParser());
    app.use(express.static(__dirname + '/public'));
    
    var ipaddress = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
    var port = process.env.OPENSHIFT_NODEJS_PORT || 3000; //6969;
    var services = {},
        config = require('./middleware/api/config')(process.env);
    
    require('./middleware/api')(app, services, config);
    console.log('Express server listening on port ' + port);
    var server = app.listen(port, ipaddress); 
    module.exports = server;
    

    test.js:

    var chai = require('chai');
    var chaiHttp = require('chai-http');
    var should = chai.should();
    var expect = require('chai').expect;
    var server = require('../');
    
    chai.use(chaiHttp);
    chai.should();
    
    describe("Booking Tests", function(){
        it("A Booking should be made on api/booking/ POST", function(done){
                 chai.request(server)
                    .post('/api/booking')
                    .send({"purpose": "Purpose 4", "startDate": "2016-03-20", "endDate": "2016-03-22", "startTime": "01:30", "endTime": "03:30", "requestor": { "email": "XXX@gmail.com" }, "roomNumber": "111"})
                    .end(function(err, res){
                        res.should.have.status(200);
                        res.should.be.json;
                        done();
                    })
            });
    
    
    });
    

    测试报告:

    <testsuite name="Mocha Tests" tests="2" failures="1" errors="1" skipped="0" timestamp="Sun, 27 Mar 2016 05:18:21 GMT" time="0.049">
    <testcase classname="Booking Tests" name="A Booking should be made on api/booking/ POST" time="0.04"/>
    <testcase classname="Booking Tests" name="A Booking should be made on api/booking/ POST" time="0.04"/>
    </testsuite>
    

    测试 - “应该在api / booking / POST上进行预订”运行两次。在我的测试文件中只有一个测试,但报告显示2个测试执行 - 1个通过,1个失败。 请让我在哪里出错。

0 个答案:

没有答案