Question

i got a problem with jsunit-maven2-plugin.

<configuration>
    <sourceDirectory>.</sourceDirectory>
    <sources>
        <source>src/test/resources/javascript/test.js</source>
    </sources>
    <testSuites>
        <testSuite>
            <name>Simple</name>
        </testSuite>
    </testSuites>
</configuration>

This is my test.js:

function SimpleTest_test() { }
function SimpleTest() { }
SimpleTest.prototype = new TestSuite();
SimpleTest.prototype.test = SimpleTest_test;
TestSuite.call(SimpleTest);

I only got a exception i can't comprehend:

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution test of goal de.berlios.jsunit:jsunit-maven2-plugin:1.3:jsunit-test failed: undefined is not a function.
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:110)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more
Caused by: TypeError: undefined is not a function. (JsUnit; line 1810)
        at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597)
        at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:557)
        at org.mozilla.javascript.NativeGlobal.typeError1(NativeGlobal.java:567)
        at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1182)
        at org.mozilla.javascript.gen.c112.call(JsUnit:1810)
        at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1191)
        at org.mozilla.javascript.BaseFunction.applyOrCall(BaseFunction.java:431)
        at org.mozilla.javascript.BaseFunction.execMethod(BaseFunction.java:179)
        at org.mozilla.javascript.IdFunction.call(IdFunction.java:78)
        at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1191)
        at org.mozilla.javascript.gen.c245.call(test.js:5)
        at org.mozilla.javascript.gen.c245.exec(test.js)
        at org.mozilla.javascript.Context.evaluateReader(Context.java:820)
        at de.berlios.jsunit.JsUnitRhinoRunner.load(JsUnitRhinoRunner.java:109)
        at de.berlios.jsunit.maven2.JsUnitMojo.execute(JsUnitMojo.java:192)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        ... 20 more
Was it helpful?

Solution

Ok, this one works well:

function Case() {
};
Case.prototype = TestCase.prototype;

function MathTest(name) {
    TestCase.call(this, name);
}
MathTest.prototype = new Case();

MathTest.prototype.testAddition = function() {
    this.assertEquals(1 + 1, 2);
}

Notice: If the test fails, maven print Tests run: 0, Failures: 0, Errors: 0, Skipped: 0,

but the Build state ends by BUILD FAILURE.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top