"nicolas de loof" <[EMAIL PROTECTED]> writes: > FYI I've started a javascript plugin project as part of maven Mojo. It > allready support running jsunit tests : > > http://svn.codehaus.org/mojo/trunk/sandbox/javascript-maven-tools >
Ah ah, that's good. I was a bit lost with all those javascript plugins laying around... I used maven-jstools as a base because I a mostly interested irght now in jsdoc and jslint, not packing. > You can look at javascript-maven-plugin JsUnitMojo, that runs a customized > TestCase with a shared jsUnit server to avoid the server-per-test issue you > noticed. > > You will not be able to run the plugin as many dependencies are not (yet) > available in central repo. Could'nt you make them available ? Or give directions on how to build these dependencies ? I assume these are the static files for jsunit runner. I could build them myself. > You can look at the src/it projects on how to configure and use the plugin > for jsunit tests. > > Could you give me an example of the test result generated from jsunit result > ? This part of the plugin is far perfectible, and I would welcome > contribution ;-) > I just wrote a mapper class that constructs a TestResult object from the results generated by jsunit: public class BrowseResultToJUnitResult { private TestResult testResult; public BrowseResultToJUnitResult(TestResult tr) { this.testResult = tr; } /** * Add all the testcases found in the given test result to this junit * TestResult. * * @param res * a BrowserResult instance. */ public void addBrowserResult(BrowserResult res) { for (final TestCaseResult tcr : res.getTestCaseResults()) { Test t = new Test() { public void run(TestResult arg0) { } public int countTestCases() { return 1; } public String toString() { return tcr.getName(); } }; testResult.startTest(t); if (!tcr.wasSuccessful()) { ResultType type = tcr.getResultType(); if (type == ResultType.ERROR) { testResult.addError(t, new Exception(tcr.getError())); } else if (type == ResultType.FAILURE) { testResult.addFailure(t, new AssertionFailedError(tcr .getFailure())); } } testResult.endTest(t); } } } and here are the tests: public class MapAcceptorToTestResultTest extends TestCase { public void testLoadResultFileAndCreateTestResult() throws IOException { String xml = "acceptor-sample.xml"; String value = xmlAsString(xml); BrowserResultBuilder builder = new BrowserResultBuilder( new DummyBrowserSource("toto", 1)); BrowserResult res = builder.build(value); TestResult tr = new TestResult(); BrowseResultToJUnitResult jres = new BrowseResultToJUnitResult(tr); jres.addBrowserResult(res); assertEquals(8, tr.runCount()); assertEquals(0, tr.errorCount()); } public void testLoadResultWithFailuresAndCreateTestResult() throws IOException { String xml = "acceptor-sample2.xml"; String value = xmlAsString(xml); BrowserResultBuilder builder = new BrowserResultBuilder( new DummyBrowserSource("toto", 1)); BrowserResult res = builder.build(value); TestResult tr = new TestResult(); BrowseResultToJUnitResult jres = new BrowseResultToJUnitResult(tr); jres.addBrowserResult(res); assertEquals(8, tr.runCount()); assertEquals(0, tr.errorCount()); assertEquals(1, tr.failureCount()); } private String xmlAsString(String xml) throws IOException { String value; InputStream is = getClass().getResourceAsStream(xml); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] data = new byte[1024]; int ln = 0; while ((ln = is.read(data, 0, 1024)) != -1) { bos.write(data, 0, ln); } return bos.toString(); } } You then just need to modify StandaloneTest (or any other test casse btw)with: @Override public void run(TestResult result) { try { setUp(); testStandaloneRun(); tearDown(); BrowseResultToJUnitResult res = new BrowseResultToJUnitResult( result); for (BrowserResult br : this.testRunResult.getBrowserResults()) res.addBrowserResult(br); } catch (Throwable e) { e.printStackTrace(); } } public void testStandaloneRun() throws Exception { testRunManager.runTests(); this.testRunResult = testRunManager.getTestRunResult(); } This is far from perfect: I should encapsulate each browser execution in a TEstSuite to have some grouping effect, but you got the idea. BTW, there are hardcoded paths in the mojos code. Is this ok? for ( int i = 0; i < browsers.length; i++ ) { if ( new File( browsers[i] ).exists() ) { continue; } if ( "firefox".equalsIgnoreCase( browsers[i] ) ) { browsers[i] = "c:/program files/Mozilla Firefox/firefox.exe"; } if ( "iexplorer".equalsIgnoreCase( browsers[i] ) ) { browsers[i] = "c:/program files/internet explorer/iexplore.exe"; } } > Nico. > > > 2007/10/22, Insitu <[EMAIL PROTECTED]>: >> >> Hello, >> I am working on integrating jsunit (http://www.jsunit.net) into >> maven. I would like to share some thoughts and request some advices >> avout the best way to do that integration. >> >> Right now, I have a sample (maven) project that executes jsunit tests >> from maven and generates reports. What I did is: >> - modify jsunit java server test cases to generate JUnit test results >> from jsunit test results: That way javascript unit tests results >> and error gets integrated seamlessly into surefire's reports >> - package the java server as an artifact >> - encapsulates all tests in a single JUnit tests cases that >> configures things and laucn jsunit's StandaloneTest class >> >> Some problems are: >> - test pages contains hardwired and absolute references to everything >> (ie. scripts and jsunti base directory) which is BAD ! >> - you need to install jsunit somewhere locally >> - you need to modify and track files by hand outside of the scope of >> the project >> - test server is started once for each test execution or event each >> JUnit test class execution which can be a performance bottleneck >> for large and/or deep projects >> >> What I want to do is: >> 1. package jsunit runner and support files as a jar or zip >> 2. create a plugin tbound to process-test-sources that would unpack >> the jsunit site in target/jsunit-runner >> 3. configure generically test server/runners to have >> target/jsunit-runner as their root site. This implies that >> javascript source files, test files and test pages be moved to >> this directory too... >> >> Ideally, I would rather serve everything from a servlet launched >> through jetty with the adequate maven plugin but this would require >> heavy changes to jsunit java server code. Or may be not... >> >> Comments and ideas are welcomed, >> >> regards, >> -- >> OQube < software engineering \ génie logiciel > >> Arnaud Bailly, Dr. >> \web> http://www.oqube.com >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> -- OQube < software engineering \ génie logiciel > Arnaud Bailly, Dr. \web> http://www.oqube.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]