General
It all depends on your testing needs. JsUnit is an implementation of JUnit in javascript, and as such it is a tool to verify javascript code with more javascript code (nothing wrong with that). JsTester was born on the need to verify javascript code outbound from the server to a client. In this way, and integration test can verify the code before the actual client does the interpreting and possible crashes.
[top] |
Follow the instructions on HowTo:Testing using JsTester.
Don't forget to call onSetup()
inside a method marked with @Before and
onTearDown()
inside a method marked with @After.
Remember that you must use the jdk15
version and that you only need junit4.jar on the classpath.
[top] |
Follow the instructions as with JUnit4, but use TestNG's annotations instead.
You may use
any version (jdk14 or jdk15) and you only need testng.jar in your classpath.
[top] |
Extend GroovyJsTestCase, that's all =)
You may use
any version (jdk14 or jdk15) and you need junit.jar in your classpath.
Here is an example using GStrings with variable interpolation:
import net.sf.jstester.ext.GroovyJsTestCase class GroovyJsTesCaseTest extends GroovyJsTestCase { void testScript(){ def groovyVar = "10"; def script = """ var counter = 0; function count(){ counter++; } for( i = 0; i < $groovyVar; i++ ){ count(); } """; eval( script ); assertExpressionEquals( "$groovyVar", "counter" ); } }
[top] |
The initial assert* methods reflect those available in JUnit's Assert
(except assertSame
), but JsTester has a built-in feature to invoke your own
validations: assertUnaryPredicate()
and assertBinaryPredicate()
.
[top] |