Recommended structure for testing Javascript with QUnit in ASP.NET

后端 未结 3 781
小蘑菇
小蘑菇 2021-02-07 03:51

I have a standard ASP.NET MVC (version 2 preview 2) solution with the actual project and server-side unit tests in separate projects.

Because this project is very clie

3条回答
  •  攒了一身酷
    2021-02-07 04:26

    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?

    Say your MVC project is MyProj.Web and your QUnit test project is MyProj.ClientTest (replace with your project names).

    • Create a Scripts folder in your ClientTest project.

    • From Project > MyProj.ClientTest Properties > Build Events, add the following to Pre-build event command line:

      XCOPY "$(SolutionDir)MyProj.Web\Scripts" "$(ProjectDir)Scripts" /S /Y

    • Then in your HTML just include the appropriate JavaScript files from the Scripts folder.

    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.

提交回复
热议问题