我遇到了jsunit-maven2-plugin的问题。
<configuration>
<sourceDirectory>.</sourceDirectory>
<sources>
<source>src/test/resources/javascript/test.js</source>
</sources>
<testSuites>
<testSuite>
<name>Simple</name>
</testSuite>
</testSuites>
</configuration>
这是我的test.js:
function SimpleTest_test() { }
function SimpleTest() { }
SimpleTest.prototype = new TestSuite();
SimpleTest.prototype.test = SimpleTest_test;
TestSuite.call(SimpleTest);
我只能得到一个我无法理解的例外:
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
答案 0 :(得分:0)
好的,这个效果很好:
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);
}
注意:如果测试失败,请打印Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
,
但Build状态以BUILD FAILURE
结束。