本文介绍了同时使用Requirejs和Knockoutjs的Visual Studio的带有Chutzpah的Test Runner无法识别QUnit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Chutzpah来获得VS 2013测试资源管理器,以在我将require.js与剔除js结合使用时识别QUnit测试

I'm trying to get VS 2013 test explorer with Chutzpah to recognize QUnit tests while I'm using require.js in combination with knockoutjs

我在下面找到了一些很好的资源,但是我想我必须缺少一小部分.

I've found some good resources listed below but I think I must just have one missing piece.

  • This is what I used to ensure I was using Qunit and require.js together correctly.

通过此资源,听起来我需要一个Chutzpah. json文件.

From this resource, it sounds like I need a Chutzpah.json file as well.

这是我可以复制的内容:

Here is what I can reproduce:

  • 如果我只使用Chutzpah和qunit,我可以使其正常工作,所以我知道我已经为VS测试跑步者正确安装了Chutzpah.

示例:testThatWorks.js

        test("test that shows up in test explorer", function () {
            equal("444test", "444test");
        });

  • 如果在浏览器中查看index.html,它将以正确的结果运行我的测试.
  • 如果我使用define语法,它也可以工作
  • 示例:testThatAlsoWorks.js

    define(
    function () {
    
        test("Test that also shows up in test explorer.", function () {
            equal("444test", "444test");
        });
    
    });
    

    • 如果我使用require语法包含其他任何资源,它将失败(这会加载剔除,但实际上并没有使用它)
    • 示例:testThatDoesn'tWork.js

      define(['knockout'],
      function (ko) {
      
          test("Test that doesn't show up in test explorer.", function () {
              equal("444test", "444test");
          });
      });
      

      这是VS 2013 Test Explorer显示的内容:

      This is what VS 2013 Test explorer shows:

      这是相关的项目设置(我的真实项目还有其他文件,但是我想在这里保持简单):

      Here is the relevant project setup (there are other files for my real project but I'm trying to keep it simple here):

      index.html (think I won't need this once I get it working in VS test runner)
      tests
         references
            qunit.css
            qunit.js
            qunit.html
         chutzpah.json
         unittestsmain.js (think I won't need this once I get it working in VS test runner)
         testThatWorks.js
         testThatDoesntWork.js
         testThatAlsoWorks.js
      Scripts
         jquery stuff
         require.js stuff
         knockout stuff
         ...
      

      这是我的chutzpah.json

      Here is my chutzpah.json

      {
         "Framework": "qunit",
         "TestHarnessReferenceMode": "AMD",
         "TestHarnessLocationMode": "SettingsFileAdjacent",
         "References" : [
            {"Path" : "../Scripts/require.js" }
         ]
      }
      

      这是Chutzpah.log文件中的超时错误

      This is the timeout error in the Chutzpah.log file

      推荐答案

      我的错误是由于未对依赖项使用正确的路径"引起的.如果将testthatdoesntwork.js文件更改为:

      My error was caused by not using the correct "paths" for the dependencies. The example I show above works if the testthatdoesntwork.js file is changed to:

      define(['../Scripts/knockout-3.1.0'],
      function (knockout) {
          test("Test that doesn't show up in test explorer.", function () {
              equal("444test", "444test");
          }); 
      });
      

      和Chutzpah.json文件如下:

      and the Chutzpah.json file looks like:

      {
      "Framework": "qunit",
      "TestHarnessReferenceMode": "AMD",
      "TestHarnessLocationMode": "SettingsFileAdjacent",
      "References" : [
           {"Path" : "../Scripts/knockout-3.1.0.js" },
           {"Path" : "../Scripts/require.js" }
      
      ]
      }
      

      查看 https://chutzpah.codeplex.com/workitem/214 和 https://stackoverflow.com/a/22124292/451736 帮助我弄清了我遇到的问题.

      Looking at https://chutzpah.codeplex.com/workitem/214 and https://stackoverflow.com/a/22124292/451736 helped me figure out the problem I was having.

      Chutzpah.json文件中的引用顺序似乎也很重要,因为在其他所有内容相同且json文件更改为下面的情况下,测试不会显示.

      It also appears that the order of the References in the Chutzpah.json file matter because with everything else the same and the json file changed to the below the test doesn't show.

      {
      "Framework": "qunit",
      "TestHarnessReferenceMode": "AMD",
      "TestHarnessLocationMode": "SettingsFileAdjacent",
      "References" : [
           {"Path" : "../Scripts/require.js"} ,
           {"Path" : "../Scripts/knockout-3.1.0.js"}
      
      ]
      }
      

      这篇关于同时使用Requirejs和Knockoutjs的Visual Studio的带有Chutzpah的Test Runner无法识别QUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 11:56