开发者

Wrapping JsUnit in JUnit

开发者 https://www.devze.com 2023-01-30 04:57 出处:网络
I\'m required to use JSUnit in my Spring-MVC project. It seems that I could write some test pages, include some of my js files, write some tests, and load up my pages with the testRunner. Fine.

I'm required to use JSUnit in my Spring-MVC project. It seems that I could write some test pages, include some of my js files, write some tests, and load up my pages with the testRunner. Fine.

But the jsunit download comes with a jsunit.jar, which implies to me that I should be able to control this process from a JUnit test. Maybe even without a test page? I don't know, because I can't find any examples of how to use jsunit.jar.

I'd much rather see some examples than instantiate every class contained in the jar file and see what methods it has available, and surely you all can sympathize. Can someone either point me to some examples or paste in a simple one here to get me started?

Many thanks.

Edit

My goal is to wrap JsUnit in JUnit, so that I can right click on the project and run as JUnit, and have my JsUnit test suite executed (so I have renamed my question to reflect my intentions). If jsunit.jar is not the way to go, then perhaps someone knows another way, i.e. loading up test pages with Selenium, or something else. I have seen some solutions that run the test suite when I build the project, and while this may indeed be handy, it is not the solution I开发者_运维百科 seek. I want my test suite to be run locally in an automated fashion, not just when I deploy, and I want them to be launched from my JUnit test suite so that I don't require two different processes to run all my tests.

Edit

From jsunit.net:

The JsUnit server addresses 3 needs:

  1. Logging of results as XML (in the same format that JUnit uses)
  2. Running JsUnit tests from JUnit or Ant on one or more browsers
  3. Running JsUnit tests from JUnit or Ant on one or more remote machines, each of which has different OSs and browsers

Clearly JsUnit tests can be run from JUnit. Surely somebody has done this before. Examples please!!


As you mentioned, the jsUnit team has implemented this:

  • http://jsunit.berlios.de/reports/jsunit/index.html
  • http://developer.berlios.de/projects/jsunit/

The test for their JsUnitRhinoRunner should get you started:

http://jsunit.berlios.de/reports/jsunit/xref-test/de/berlios/jsunit/JsUnitRhinoRunnerTest.html

This is part of the jsUnit Java source.


So you want to wrap your JsUnit tests into JUnit. What about using Maven to run those tests? There is a fine plugin for that: Maven-testlol-plugin. It runs test js files without starting a browser, using Rhino javascript engine and envjs for simulating a browser environment.

0

精彩评论

暂无评论...
验证码 换一张
取 消