]> source.dussan.org Git - gwtquery.git/commitdiff
Added a module to speed up testing in development mode
authorManolo Carrasco <manolo@apache.org>
Wed, 12 May 2010 13:47:14 +0000 (13:47 +0000)
committerManolo Carrasco <manolo@apache.org>
Wed, 12 May 2010 13:47:14 +0000 (13:47 +0000)
devtest/README.txt [new file with mode: 0644]
devtest/pom.xml [new file with mode: 0644]
devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml [new file with mode: 0644]
devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java [new file with mode: 0644]
devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java [new file with mode: 0644]
devtest/src/main/java/com/google/gwt/query/public/test.html [new file with mode: 0644]
pom.xml

diff --git a/devtest/README.txt b/devtest/README.txt
new file mode 100644 (file)
index 0000000..54b9d5a
--- /dev/null
@@ -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 (file)
index 0000000..2f9c643
--- /dev/null
@@ -0,0 +1,79 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.google.gwt</groupId>
+        <artifactId>gwtquery-project</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>devtest</artifactId>
+    <packaging>jar</packaging>
+    <name>dev-mode for testing</name>
+    <dependencies>
+        <dependency>
+            <groupId>${groupId}</groupId>
+            <artifactId>gwtquery</artifactId>
+            <version>${version}</version>
+            <type>jar</type>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>${groupId}</groupId>
+            <artifactId>gwtquery-plugins</artifactId>
+            <version>${version}</version>
+            <type>jar</type>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+    <build>
+       <outputDirectory>./target/www/WEB-INF/classes</outputDirectory>
+        <resources>
+            <resource>
+                <directory>${basedir}/src/main/java</directory>
+            </resource>
+            <resource>
+                <directory>${basedir}/src/main/resources</directory>
+            </resource>
+        </resources>
+        <testResources>
+            <testResource>
+                <directory>${basedir}/src/test/java</directory>
+            </testResource>
+            <testResource>
+                <directory>${basedir}/src/test/resources</directory>
+            </testResource>
+        </testResources>
+
+        <plugins>
+
+        <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>gwt-maven-plugin</artifactId>
+            <configuration>
+                <style>PRETTY</style>
+                <gwtVersion>${gwtversion}</gwtVersion>
+                <modules>
+                    <module>com.google.gwt.query.DevTestRunner</module>
+                </modules>
+                <runTarget>test/test.html</runTarget>
+                <hostedWebapp>target/www</hostedWebapp>
+                <soyc>true</soyc>
+            </configuration>
+<!--
+        <executions>
+          <execution>
+            <phase>prepare-package</phase>
+            <goals>
+              <goal>compile</goal>
+            </goals>
+          </execution>
+        </executions>
+-->
+      </plugin>
+
+        </plugins>
+    </build>
+</project>
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 (file)
index 0000000..537f0c4
--- /dev/null
@@ -0,0 +1,5 @@
+<module rename-to="test">
+    <inherits name='com.google.gwt.query.Query'/>
+    <entry-point class='com.google.gwt.query.client.DevTestRunner'/>
+</module>
+    
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 (file)
index 0000000..046fdf1
--- /dev/null
@@ -0,0 +1,50 @@
+/*\r
+ * Copyright 2009 Google Inc.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not\r
+ * use this file except in compliance with the License. You may obtain a copy of\r
+ * the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+ * License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+package com.google.gwt.query.client;\r
+\r
+import static com.google.gwt.query.client.GQuery.$;\r
+\r
+import com.google.gwt.core.client.EntryPoint;\r
+\r
+/**\r
+ * This module is thought to emulate a test environment similar to\r
+ * GWTTestCase, but running it in development mode.\r
+ * \r
+ * The main goal of it is to execute tests in a faster way, because you only need\r
+ * to push reload in your browser.\r
+ * \r
+ * @author manolo\r
+ * \r
+ */\r
+public class DevTestRunner extends MyTestCase implements EntryPoint {\r
+\r
+  public void onModuleLoad() {\r
+    gwtSetUp();\r
+    testDomManip();\r
+  }\r
+\r
+  public void testDomManip() {\r
+    String content = "<span class='branchA'><span class='target'>branchA target</span></span>"\r
+      + "<span class='branchB'><span class='target'>branchB target</span></span>";\r
+    \r
+    $(e).html("");\r
+    $(e).append(content);\r
+    assertEquals(4, $("span", e).size());\r
+    assertEquals(2, $("span.target", e).size());\r
+    assertHtmlEquals(content, $(e).html());\r
+  }\r
+  \r
+}\r
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 (file)
index 0000000..e505812
--- /dev/null
@@ -0,0 +1,69 @@
+/*\r
+ * Copyright 2009 Google Inc.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not\r
+ * use this file except in compliance with the License. You may obtain a copy of\r
+ * the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+ * License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+package com.google.gwt.query.client;\r
+\r
+import com.google.gwt.dom.client.Element;\r
+import com.google.gwt.user.client.ui.HTML;\r
+import com.google.gwt.user.client.ui.RootPanel;\r
+\r
+/**\r
+ * Just a simple class to emulate JUnit TestCase\r
+ */\r
+public class MyTestCase {\r
+\r
+  static Element e = null;\r
+  static HTML testPanel = null;\r
+\r
+  public void gwtSetUp() {\r
+    if (e == null) {\r
+      testPanel = new HTML();\r
+      RootPanel.get().add(testPanel);\r
+      e = testPanel.getElement();\r
+      e.setId("core-tst");\r
+    } else {\r
+      e.setInnerHTML("");\r
+    }\r
+  }\r
+  \r
+  public static void assertNotNull(Object a) {\r
+    check(a != null, "assertNotNull: actual object is null");\r
+  }\r
+\r
+  public static void assertEquals(Object a, Object b) {\r
+    check(a.equals(b), "assertEquals: expected=" + a + " actual=" + b);\r
+  }\r
+  \r
+  public static void check(boolean condition, String message) {\r
+    if (!condition) {\r
+      RuntimeException e = new RuntimeException(message);\r
+      e.printStackTrace();\r
+      throw e;\r
+    }\r
+  }\r
+  \r
+  protected static void assertHtmlEquals(Object expected, Object actual) {\r
+    assertEquals(iExplorerFixHtml(expected), iExplorerFixHtml(actual));\r
+  }\r
+\r
+  protected static String iExplorerFixHtml(Object s) {\r
+    return s.toString().trim().toLowerCase().\r
+        replaceAll("[\r\n]", "").\r
+        replaceAll(" ([\\w]+)=[\"']([^\"']+)[\"']", " $1=$2").\r
+        replaceAll("\\s+\\$h=\"[^\"]+\"", "").\r
+        replaceAll(" added=[^ >]+", "");\r
+  }\r
+  \r
+}\r
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 (file)
index 0000000..1c44785
--- /dev/null
@@ -0,0 +1,8 @@
+<html>\r
+  <head>\r
+    <script language="javascript" src="test.nocache.js"></script>\r
+  </head>\r
+  <body>\r
+  </body>\r
+</html>\r
+    
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index c0a056c578953d8354e6b21a4f1e3033f22c5bb5..d55ea1aa0c65fd3cc5fee45751e440fc97e28b31 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -49,6 +49,7 @@
         <module>gwtquery-core</module>
         <module>plugins</module>
         <module>samples</module>
+        <module>devtest</module>
     </modules>
 
     <distributionManagement>