mocha + mocha.parallel-并行运行API测试,并可以通过某些特殊标签运行

时间:2018-08-02 09:10:57

标签: node.js mocha web-api-testing parallel-testing

当前,我们有一个基于Mocha + mocha.parallel的API测试框架。 在我们决定使用--grep功能来改善烟雾之前,它的工作非常出色。

我们以这种方式编写的测试:

import parallel = require("mocha.parallel");
    parallel("Paralell 1", function() {
    [
        {descript: "Suite1 test# "},
        {descript: "Suite1 test# @TAG"},
        {descript: "Suite1 test# "},
        {descript: "Suite1 test# "},
        {descript: "Suite1 test# @TAG "},
    ].forEach((testData, index) => {
        it(`${testData.descript} ${index} testing of feature`, function(done) {

            console.log(`I'm in test ${testData.descript}  ${index} body`);
            setTimeout(done, 2000);
        });
    });
});
parallel("Parallel 2", function() {
    [
        {descript: "Suite2 test# "},
        {descript: "Suite2 test# "},
        {descript: "Suite2 test# "},
        {descript: "Suite2 test# "},
        {descript: "Suite2 test# "},
        {descript: "Suite2 test# "},
    ].forEach((testData, index) => {
        it(`${testData.descript} ${index} testing of feature`, function(done) {
            console.log(`I'm in test ${testData.descript}  ${index}  body`);
            setTimeout(done, 2000);
        });
    });
});

运行测试时,我们发现了2个问题

  1. 当我们运行一些测试文件时-数据数组中的所有测试都将运行 enter image description here

  2. 当我们运行所有测试时-运行某些测试而其他测试失败

  

TypeError:无法读取null的属性“ then”

如果我们将Parallels像这样并行放置,我们可以模拟这样的问题:

parallel("Paralell 3", function() {    
    parallel("Paralell 1", function() {
        .....
    });
    parallel("Parallel 2", function() {
       .....
   });    
});

enter image description here

问题:

  1. 如何解决此类问题
  2. 任何可以帮助我们并行运行现有mocha测试并能够仅使用一个数据集(带有标签或任何其他指针)运行的库

0 个答案:

没有答案