# HG changeset patch # User Jaroslav Tulach # Date 1358890959 -3600 # Node ID 3cefccd50bd5b1990be8e2f90ead42eb57b0040e # Parent 715a6c77b19e8956cd33866569c1d3a953ff82f0 Showing how to write inconsistency and integration tests diff -r 715a6c77b19e -r 3cefccd50bd5 mojo/src/main/resources/META-INF/maven/archetype-metadata.xml --- a/mojo/src/main/resources/META-INF/maven/archetype-metadata.xml Tue Jan 22 22:11:52 2013 +0100 +++ b/mojo/src/main/resources/META-INF/maven/archetype-metadata.xml Tue Jan 22 22:42:39 2013 +0100 @@ -35,7 +35,7 @@ src/test/java - **/AppTest.java + **/*Test.java diff -r 715a6c77b19e -r 3cefccd50bd5 mojo/src/main/resources/archetype-resources/pom.xml --- a/mojo/src/main/resources/archetype-resources/pom.xml Tue Jan 22 22:11:52 2013 +0100 +++ b/mojo/src/main/resources/archetype-resources/pom.xml Tue Jan 22 22:42:39 2013 +0100 @@ -59,5 +59,11 @@ 6.5.2 test + + ${project.groupId} + vmtest + 0.3-SNAPSHOT + test + diff -r 715a6c77b19e -r 3cefccd50bd5 mojo/src/main/resources/archetype-resources/src/main/resources/index.xhtml --- a/mojo/src/main/resources/archetype-resources/src/main/resources/index.xhtml Tue Jan 22 22:11:52 2013 +0100 +++ b/mojo/src/main/resources/archetype-resources/src/main/resources/index.xhtml Tue Jan 22 22:42:39 2013 +0100 @@ -6,7 +6,7 @@

Loading Bck2Brwsr's Hello World...

- Your name: + Your name:

diff -r 715a6c77b19e -r 3cefccd50bd5 mojo/src/main/resources/archetype-resources/src/test/java/AppTest.java --- a/mojo/src/main/resources/archetype-resources/src/test/java/AppTest.java Tue Jan 22 22:11:52 2013 +0100 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/AppTest.java Tue Jan 22 22:42:39 2013 +0100 @@ -4,7 +4,9 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -/** Demonstrating POJO testing of HTML page model. +/** Demonstrating POJO testing of HTML page model. Runs in good old HotSpot + * as it does not reference any HTML elements or browser functionality. Just + * operates on the page model. * * @author Jaroslav Tulach */ diff -r 715a6c77b19e -r 3cefccd50bd5 mojo/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java Tue Jan 22 22:42:39 2013 +0100 @@ -0,0 +1,40 @@ +package ${package}; + +import org.apidesign.bck2brwsr.vmtest.Compare; +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.testng.annotations.Factory; + +/** Bck2brwsr cares about compatibility with real Java. Whatever API is + * supported by bck2brwsr, it needs to behave the same way as when running + * in HotSpot VM. + *

+ * There can be bugs, however. To help us fix them, we kindly ask you to + * write an "inconsistency" test. A test that compares behavior of the API + * between real VM and bck2brwsr VM. This class is skeleton of such test. + * + * @author Jaroslav Tulach + */ +public class InconsistencyTest { + /** A method to demonstrate inconsistency between bck2brwsr and HotSpot. + * Make calls to an API that behaves strangely, return some result at + * the end. No need to use any assert. + * + * @return value to compare between HotSpot and bck2brwsr + */ + @Compare + public int checkStringHashCode() throws Exception { + return "Is string hashCode the same?".hashCode(); + } + + /** Factory method that creates a three tests for each method annotated with + * {@link org.apidesign.bck2brwsr.vmtest.Compare}. One executes the code in + * HotSpot, one in Rhino and the last one compares the results. + * + * @see org.apidesign.bck2brwsr.vmtest.VMTest + */ + @Factory + public static Object[] create() { + return VMTest.create(InconsistencyTest.class); + } + +} diff -r 715a6c77b19e -r 3cefccd50bd5 mojo/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java Tue Jan 22 22:42:39 2013 +0100 @@ -0,0 +1,46 @@ +package ${package}; + +import org.apidesign.bck2brwsr.htmlpage.api.OnEvent; +import org.apidesign.bck2brwsr.vmtest.BrwsrTest; +import org.apidesign.bck2brwsr.vmtest.HtmlFragment; +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.testng.annotations.Factory; + +/** Sometimes it is useful to run tests inside of the real browser. + * To do that just annotate your method with {@link org.apidesign.bck2brwsr.vmtest.BrwsrTest} + * and that is it. If your code references elements on the HTML page, + * you can pass in an {@link org.apidesign.bck2brwsr.vmtest.HtmlFragment} which + * will be made available on the page before your test starts. + * + * @author Jaroslav Tulach + */ +public class IntegrationTest { + + /** Write to testing code here. Use assert (but not TestNG's + * Assert, as TestNG is not compiled with target 1.6 yet). + */ + @HtmlFragment( + "

Loading Bck2Brwsr's Hello World...

\n" + + "Your name: \n" + + "\n" + + "

\n" + + " \n" + + "

\n" + ) + @BrwsrTest + public void modifyValueAssertChangeInModel() { + Index m = new Index(); + m.setName("Joe Hacker"); + m.applyBindings(); + assert "Joe Hacker".equals(m.INPUT.getValue()) : "Value is really Joe Hacker: " + m.INPUT.getValue(); + m.INPUT.setValue("Happy Joe"); + m.triggerEvent(m.INPUT, OnEvent.CHANGE); + assert "Happy Joe".equals(m.getName()) : "Name property updated to Happy Joe: " + m.getName(); + } + + @Factory + public static Object[] create() { + return VMTest.create(IntegrationTest.class); + } + +}