21

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 client-side heavy, I want to make a ClientTest project as well that uses QUnit to test the main project.

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?

1
  • How did it all ended up. Could you share a sample?
    – Shad
    Jun 15, 2023 at 6:55

3 Answers 3

17

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.

2
  • 4
    Consider including the following instruction first. Otherwise there's a risk of having orphaned files accumulating in the target directory. DEL "$(ProjectDir)Scripts\Web\*.js" "web" is the sub directory into which I copy the .js files to be tested.
    – Aaron
    Apr 8, 2014 at 8:13
  • Could you share a sample?
    – Shad
    Jun 15, 2023 at 6:55
6

Perhaps you could pick and choose techniques from this article, including using the command-line, harnessing NUnit with WatiN, and scraping test results for reporting. This solution wouldn't require a separate WebForms project to harness the tests in, since it's all handled by WatiN.

1
  • Using WaitiN is an interesting idea, but not exactly what I want. Since on the client side I have a whole MVC framework running I want to have tests that aren't visual at all, and I also don't want to have test pages in the main project.
    – wm_eddie
    Oct 21, 2009 at 3:27
2

It's not too clear to me why using MVC makes a difference - if you want to integrate your tests into a CI build then gWiz's suggestion is the route to go.

If your requirement is that you want to run your tests interactively directly on the real page without affecting the look of that page then you could check out the FireUnit plugin for Firebug. You can also wrap FireUnit around QUnit as described on John Resig's blog.

If you're concerned about including test stuff then include the relevant scripts in your test/debug builds and disable/remove them in your production builds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.