在TFS 2012中运行Jasmine的Chutzpah无法找到受测试的参考文件 [英] Chutzpah running Jasmine in TFS 2012 can't find referenced file under test

查看:177
本文介绍了在TFS 2012中运行Jasmine的Chutzpah无法找到受测试的参考文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Chutzpah进行我们的Jasmine测试。
我已将Chutzpah dll添加到解决方案中并更新构建以运行* .js测试。

I am using Chutzpah to run our Jasmine tests. I have added the Chutzpah dlls to the solution and updated the build to run *.js tests.

项目结构如下:

MyApp.Web
    Scripts
        App
            Home 
                DateControl.js 
MyApp.Web.Tests 
    Scripts 
        Jasmine 
        lib
            Chutzpah (dlls) 
        Spec 
            App 
                Home 
                    DateControlSpecs.js

Jasmine测试文件使用引用标记来引用要测试的文件

The Jasmine test file uses a reference tag to reference the file to be tested

/// <reference path="../../../../../../App.web/scripts/app/home/datecontrol.js" />

运行Jasmine测试然后我收到以下错误:

The Jasmine tests are run however I get the following error:

ReferenceError: Can't find variable: dateControl in file

dateControl是被测对象。
如果我将要测试的代码复制到Jasmine测试文件中,则测试通过。
使用参考标记的jasmine测试在Visual Studio 2013中使用测试资源管理器中的Chutzpah测试适配器传递。

dateControl is the object under test. If I copy the code to be tested into the Jasmine test file then the tests pass. The jasmine tests with the reference tag pass using the Chutzpah Test Adapter in Test Explorer in Visual Studio 2013.

我不知道为什么这不起作用。

I have no idea why this is not working.

更新

@ jessehouwing的回答指出了问题的路径。

@jessehouwing's answer pointed out the route of the issue for me.

构建服务器上的构建文件夹具有以下结构

The build folder on the build server has the following structure

bin
_PublishedWebsites
src

bin _PublishedWebsites src

将jasmine测试脚本和库复制到bin,而将测试中的脚本文件复制到src目录和_publishedwebsite目录。

The jasmine test scripts and libraries are copied to bin whereas the script files under test are copied to both the src directory and the _publishedwebsite directory.

我正在寻找一个易于管理的解决方案,以便任何未来的开发人员都不需要知道他们需要将任何新脚本链接到测试项目中。

I am looking for an easy to manage solution so that any future devs do not need to know they need to link any new scripts into the test project.

推荐答案

我现在可以忍受的解决方案

对于两个茉莉花测试文件和测试中的文件我添加了始终复制根据Chutzpah文档的属性。我没有意识到被测试的文件实际上是与茉莉花测试文件一起被复制到builds bin文件夹中。
所以在构建服务器上我最终得到了以下结构

For both the jasmine test files and the files under test I added "Always copy" in properties as per the Chutzpah documentation. I didn't realise that the files under test were actually being copied to the builds bin folder along with the jasmine test files. So on the build server I ended up with the following struacture

bin
    scripts
        app
            * application js files
        specs
            * jasmine test files

在我的jasmine测试文件中,我添加了两个引用:

In my jasmine test file I add two references:


  • 第一个到要测试的文件的Visual Studio目录结构

  • 第二个构建bin文件夹结构

Hack 1

我可以通过添加对我的jasmine测试文件的另一个引用来使其工作,该文件使用构建目录的结构而不是解决方案目录结构但是再次出现错误该路径可能输入错误。

I can get it to work by adding another reference to my jasmine test file which uses the structure of the build directory and not the solution directory structure but again this is open to error as the path may be typed in incorrectly.

下面的第二个参考将允许测试在VS Test Explorer和TFS Build中运行

The second reference below will allow the tests to run in both VS Test Explorer and TFS Build

/// <reference path="../../../../../../App.Web/scripts/app/home/datecontrol.js" />
/// <reference path="../../../../../_PublishedWebsites\App.Web/scripts/app/home/datecontrol.js" />

Hack 2

通过向项目的构建后构建事件添加xcopy命令,我可以将要测试的文件复制到与jasmine测试文件相同的位置。

By adding an xcopy command to the post-build build event of the project I can copy the files to be tested into the same location as the jasmine test files.

这篇关于在TFS 2012中运行Jasmine的Chutzpah无法找到受测试的参考文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆