public abstract class JavaScriptTCK
extends java.lang.Object
Fn.Presenter
or any other system that understands
JavaScriptBody
annotation. The JavaScriptTCK
tests are headless - e.g. they don't need access to browser APIs
like DOM. It is possible to execute them in node
or in a plain ScriptEngine
environment. The tests are focused
on Java/JavaScript interactions, calls and exchange of objects between the
two worlds. See KnockoutTCK
for UI oriented tests.
Implement your system, setup your headless environment for execution of JavaScript and execute the tests. There are the steps to follow:
test classes
KOTest
annotationTypical way to iterate through all the test methods looks like this:
public final class ScriptEngineJavaScriptTCK extendsJavaScriptTCK
{ static <R> void collectTckTests(List
<R> res,Function
<Method
, R> factory) { for (Class
c : testClasses()) { for (Method
m : c.getMethods()) { if (m.getAnnotation(KOTest
.class) != null) { res.add(factory.apply(m)); } } } } }
by subclassing JavaScriptTCK
one gets access to protected
method JavaScriptTCK.testClasses()
and can obtain all the TCK classes.
One can use any factory and create objects suitable for any
testing framework. Typical invocation of a single test then looks like
Object
instance = method.getDeclaringClass().newInstance();
method.invoke(instance);
e.g. one creates an instance of the object and invokes its test method
.
When the test provided by this headless TCK are passing,
consider also testing your environment on a
visual DOM-based TCK
.
KnockoutTCK
Constructor and Description |
---|
JavaScriptTCK()
Creates and registers instance of the TCK.
|
Modifier and Type | Method and Description |
---|---|
boolean |
executeNow(java.lang.String script)
Executes JavaScript now.
|
protected static java.lang.Class<?>[] |
testClasses()
Gives you list of classes included in the TCK.
|
protected static java.lang.Class<?>[] testClasses()
KOTest
annotation. The methods are public
instance methods that take no arguments. The method should be
invoke in a presenter context Fn.activate(org.netbeans.html.boot.spi.Fn.Presenter)
.KOTest
annotationpublic boolean executeNow(java.lang.String script) throws java.lang.Exception
false
and let the TCK test terminate gracefully.script
- the script to execute in the JavaScripttrue
if the script was executed, false
if it couldn't bejava.lang.Exception
- if the script contains an errorCopyright © 2021 The Apache Software Foundation. All rights reserved.