From bd9fe1c2531df1fb5682ace03197a1aa8ded2da4 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Wed, 12 May 2010 13:47:14 +0000 Subject: [PATCH] Added a module to speed up testing in development mode --- devtest/README.txt | 22 ++++++ devtest/pom.xml | 79 +++++++++++++++++++ .../google/gwt/query/DevTestRunner.gwt.xml | 5 ++ .../gwt/query/client/DevTestRunner.java | 50 ++++++++++++ .../google/gwt/query/client/MyTestCase.java | 69 ++++++++++++++++ .../com/google/gwt/query/public/test.html | 8 ++ pom.xml | 1 + 7 files changed, 234 insertions(+) create mode 100644 devtest/README.txt create mode 100644 devtest/pom.xml create mode 100644 devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml create mode 100644 devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java create mode 100644 devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java create mode 100644 devtest/src/main/java/com/google/gwt/query/public/test.html diff --git a/devtest/README.txt b/devtest/README.txt new file mode 100644 index 00000000..54b9d5a3 --- /dev/null +++ b/devtest/README.txt @@ -0,0 +1,22 @@ + + +This module is thought to run tests in development mode in +order to speed up TDD. + +- Put your tests in the DevTestRunner class. +- Call gwtSetup() and your test in the entryPoint. +- If you need any assertion method provided by the junit + library put it in the class MyTestCase. + There are already a bunch of them. +- Run the module in development mode: mvn gwt:run + or lauch it from eclipse +- See the output of the tests. If there is a failure + a stacktrace should be shown in the output. +- Modify your test code and reload the application in your browser. +- When your test was ready put it in your test class extending + GWTTestCase. + + + + + diff --git a/devtest/pom.xml b/devtest/pom.xml new file mode 100644 index 00000000..2f9c6438 --- /dev/null +++ b/devtest/pom.xml @@ -0,0 +1,79 @@ + + 4.0.0 + + com.google.gwt + gwtquery-project + 1.0.0-SNAPSHOT + + + devtest + jar + dev-mode for testing + + + ${groupId} + gwtquery + ${version} + jar + provided + + + + ${groupId} + gwtquery-plugins + ${version} + jar + provided + + + + ./target/www/WEB-INF/classes + + + ${basedir}/src/main/java + + + ${basedir}/src/main/resources + + + + + ${basedir}/src/test/java + + + ${basedir}/src/test/resources + + + + + + + org.codehaus.mojo + gwt-maven-plugin + + + ${gwtversion} + + com.google.gwt.query.DevTestRunner + + test/test.html + target/www + true + + + + + + + diff --git a/devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml b/devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml new file mode 100644 index 00000000..537f0c47 --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java b/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java new file mode 100644 index 00000000..046fdf11 --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java @@ -0,0 +1,50 @@ +/* + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client; + +import static com.google.gwt.query.client.GQuery.$; + +import com.google.gwt.core.client.EntryPoint; + +/** + * This module is thought to emulate a test environment similar to + * GWTTestCase, but running it in development mode. + * + * The main goal of it is to execute tests in a faster way, because you only need + * to push reload in your browser. + * + * @author manolo + * + */ +public class DevTestRunner extends MyTestCase implements EntryPoint { + + public void onModuleLoad() { + gwtSetUp(); + testDomManip(); + } + + public void testDomManip() { + String content = "branchA target" + + "branchB target"; + + $(e).html(""); + $(e).append(content); + assertEquals(4, $("span", e).size()); + assertEquals(2, $("span.target", e).size()); + assertHtmlEquals(content, $(e).html()); + } + +} diff --git a/devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java b/devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java new file mode 100644 index 00000000..e505812a --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java @@ -0,0 +1,69 @@ +/* + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.query.client; + +import com.google.gwt.dom.client.Element; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.RootPanel; + +/** + * Just a simple class to emulate JUnit TestCase + */ +public class MyTestCase { + + static Element e = null; + static HTML testPanel = null; + + public void gwtSetUp() { + if (e == null) { + testPanel = new HTML(); + RootPanel.get().add(testPanel); + e = testPanel.getElement(); + e.setId("core-tst"); + } else { + e.setInnerHTML(""); + } + } + + public static void assertNotNull(Object a) { + check(a != null, "assertNotNull: actual object is null"); + } + + public static void assertEquals(Object a, Object b) { + check(a.equals(b), "assertEquals: expected=" + a + " actual=" + b); + } + + public static void check(boolean condition, String message) { + if (!condition) { + RuntimeException e = new RuntimeException(message); + e.printStackTrace(); + throw e; + } + } + + protected static void assertHtmlEquals(Object expected, Object actual) { + assertEquals(iExplorerFixHtml(expected), iExplorerFixHtml(actual)); + } + + protected static String iExplorerFixHtml(Object s) { + return s.toString().trim().toLowerCase(). + replaceAll("[\r\n]", ""). + replaceAll(" ([\\w]+)=[\"']([^\"']+)[\"']", " $1=$2"). + replaceAll("\\s+\\$h=\"[^\"]+\"", ""). + replaceAll(" added=[^ >]+", ""); + } + +} diff --git a/devtest/src/main/java/com/google/gwt/query/public/test.html b/devtest/src/main/java/com/google/gwt/query/public/test.html new file mode 100644 index 00000000..1c447858 --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/public/test.html @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index c0a056c5..d55ea1aa 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,7 @@ gwtquery-core plugins samples + devtest -- 2.39.5