推荐结构ASP.NET中使用QUnit的JavaScript测试 [英] Recommended structure for testing Javascript with QUnit in ASP.NET
问题描述
我有在不同项目的实际项目和服务器端单元测试标准的ASP.NET MVC(第2版preVIEW 2)解决方案。
I have a standard ASP.NET MVC (version 2 preview 2) solution with the actual project and server-side unit tests in separate projects.
由于这个项目是非常的客户端重,我想打一个ClientTest项目,以及使用QUnit来测试主项目。
Because this project is very client-side heavy, I want to make a ClientTest project as well that uses QUnit to test the main project.
我想过创建具有一个HTML文件,将加载各种脚本在我的脚本/目录下,并与QUnit测试他们定期ASP.NET web表单的项目。不幸的是,这将产生另一个ASP.NET开发服务器。我可以在运行测试之前配置运行MVC项目服务器的端口,但一定是一个更好的方式,不只是扔在测试HTML文件进入主MVC项目。
I've thought of creating a regular ASP.NET webforms project with a single HTML file that would load the various scripts in my Scripts/ directory and test them with QUnit. Unfortunately this will spawn another ASP.NET Development Server. I could configure the port of the running MVC project server before running the tests, but there's got to be a better way that isn't just throwing the test html file into the main MVC project.
有谁知道要去这个更好的办法?
Does anyone know of a better way of going about this?
推荐答案
我喜欢你放置QUnit测试在一个单独的项目的想法。关于使用什么 XCOPY
来在pre-生成事件的脚本复制?
I like your idea of placing the QUnit tests in a separate project. What about using XCOPY
to copy the scripts in the pre-build event?
说你的MVC项目的 MyProj.Web 并您QUnit测试项目的 MyProj.ClientTest (用你的项目名称替换)。
Say your MVC project is MyProj.Web and your QUnit test project is MyProj.ClientTest (replace with your project names).
-
在您的ClientTest项目中创建一个脚本文件夹。
Create a Scripts folder in your ClientTest project.
从的项目> MyProj.ClientTest 属性>生成事件的,添加以下的 pre-生成事件命令行:
XCOPY$(SolutionDir)MyProj.Web \\脚本$(PROJECTDIR)脚本/ S / Y
XCOPY "$(SolutionDir)MyProj.Web\Scripts" "$(ProjectDir)Scripts" /S /Y
然后在你的HTML只包含来自脚本文件夹中相应的JavaScript文件。
Then in your HTML just include the appropriate JavaScript files from the Scripts folder.
注意:您将不得不重建ClientTest项目刷新JavaScript文件,当你想重新运行测试。根据需要调整文件夹的名称,路径和 XCOPY
选项。
Note: You will have to rebuild your ClientTest project to refresh JavaScript files when you want to rerun tests. Adjust folder names, paths and XCOPY
options as needed.
这篇关于推荐结构ASP.NET中使用QUnit的JavaScript测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!