10
On FxJsJUnit an idea to test JavaScript codes with JUnit and JavaFX

On fx jsj unit - an idea to test javascript codes with junit and javafx

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: On fx jsj unit - an idea to test javascript codes with junit and javafx

On FxJsJUnitan idea to test JavaScript codes with JUnit and JavaFX

Page 2: On fx jsj unit - an idea to test javascript codes with junit and javafx

Who writes this document?

● Name : mike_neck (Twitter @mike_neck)● Jobs : No Jobs now!

○ If someone provide me a chance to have an opportunity, I will try it! So ask me!

● Technologies :○ Groovy○ JavaScript○ Java○ Erlang

● Interested in : Concurrent Programings

Page 3: On fx jsj unit - an idea to test javascript codes with junit and javafx

What's the Fx-Js-JUnit?

● An library for testing JavaScript with Type safe assertion.

● Applied JavaFX's WebEngine as a JavaScript Environment.

● Based on these ideas and environment, we can test for JavaScript with JUnit, most popular testing framework.

Page 4: On fx jsj unit - an idea to test javascript codes with junit and javafx

Usage of Fx-Js-JUnit - the sample code. - (1) Preparation for test.

@ClassRulepublic static FxJsJUnit fxJsJUnit

= FxJsJUnit.option(CoreExtension.class).address("http://www.oracle.com").identifiedBy(WebTest.class).get();

Page 5: On fx jsj unit - an idea to test javascript codes with junit and javafx

Usage of Fx-Js-JUnit - the sample code. - (2) getting IF for WebEngine.

private JsJUnit jsJUnit;

@Beforepublic void getTester() {

jsJUnit = fxJsJUnit.getTester();}

Page 6: On fx jsj unit - an idea to test javascript codes with junit and javafx

Usage of Fx-Js-JUnit - the sample code. - (3) calling JavaScript code.

@Testpublic void testStringTest () {

String result = jsJUnit.callAsString("$('#input').text;"

);assertThat(result, is ("Input Here!"));

}

Page 7: On fx jsj unit - an idea to test javascript codes with junit and javafx

Off course you can assert Plain Old JavaScript Object with POJO.

@Testpublic void personInitialization () {

Person person = new Person();person.setName("mike");person.setAge(35);Person mike = jsJUnit.callAs(

"new Person('mike', 35)", Person.class);assertThat(mike, is(person));

}

Page 8: On fx jsj unit - an idea to test javascript codes with junit and javafx

Architecture of Fx-Js-JUnit

JUnit

JavaFx

WebEngineJsJUnit

Test

Test

Test1.Launch 2.Prepare 3.execute

4.call-function

4.call-function

4.call-function5. call

Page 9: On fx jsj unit - an idea to test javascript codes with junit and javafx

TODOs and Problems/Difficulties

● Embbed Web Servers (Static Web Server) /Servlet Containers (Tomcat / Jetty) /Java EE Containers (Glassfish) to test total Enterprise Application (TODO)

● Fx-Js-JUnit cannot be applied Concurrent Test Execution. Because JavaFX cannot be launched simultaneously and multiple times without restart JVM(. It requires modification of JUnit framework). (Problem/Difficulty)○ to avoid this problem I'm going to develop gradle-

fxjsjunit-plugin and Jenkins-fsjsjunit-plugin.

Page 10: On fx jsj unit - an idea to test javascript codes with junit and javafx

Thank you for your attention.

Available resources ...● GitHub

○ https://github.com/mike-neck/FxJsJUnit● Another documents

○ http://www.slideshare.net/mikeneck/unit-testing-java-script-with-javafx■ (I'm sorry this document is written in Japanese.)