I'm having some trouble testing my application. We have some pretty complex 
hierarchical data being created and to do effective testing I want to put 
the Database into a known state before running any tests, whether that's 
empty or with a predefined set of data depends on the specific tests being 
run.


GWT Junit tests don't allow you to perform async requests during the 
beforeMethod.

To try and get around some of this I'm trying to run all my junit tests 
from my own handler. The process works kind of like this:

A. load the list of GWTTestCases
B. Ask each test whether it wants an empty database or a predefined data 
set in the DB and create the preconditions. All my tests extend a base 
class which extends GWTTestCase and has a series of flags that let it
specify the required DB state.
C. run the GWTTestCases as normal.

The first 2 steps are pretty straightforward but the third one is throwing 
me. I can't get any of the tests to run. 
I'm sure I'm not running the tests properly.

I'm getting a combination of errors both:

The test class 'com.scalebase.management.client.DummyTest' was not found in 
module 'com.scalebase.management.ScaleBaseManagement'; no compilation unit 
for that type was seen


And

GWTTestCases require a name; 
"null(com.scalebase.management.client.DummyTest)" has none.  Perhaps you 
used TestSuite.addTest() instead of addTestClass()?



Can anyone give me some guidance in how to run the GWT unit tests 
programatically? Also should I be running the tests class by class or 
should I use reflection to try and run them method by method? I'm not 
really sure how normal tools handle these issues.


Any help would be greatly appreciated
Thanks



My class looks like this:


public class NewApproach 
{
    private ServersService ss;
    private List<TestBase> tests;
    
    private void loadTests()
    {
        tests = new ArrayList<TestBase>();
        tests.add(new DummyTest());
    }
    
    private void clean() throws Exception
    {
        ss = new ServersService();
        ss.clean("1");
    }
    
    private TestResult runTest(TestBase tests) throws Exception
    {
        if(tests.isCleanBeforeRunning())
        clean();
        TestResult tr = new TestResult();
        tests.run(tr);
        return tr;
    }
    
    private void printResults(TestResult tr)
    {
        int passes = tr.runCount() - (tr.failureCount() + tr.errorCount());
        System.out.println("Ran " + tr.runCount() + " tests " + passes + " 
passed");
        System.out.println();
        while(tr.errors().hasMoreElements())
        {
            TestFailure tf  = tr.errors().nextElement();
            
            System.out.println(tf.failedTest().toString() + " error");
            System.out.println(tf.exceptionMessage());
            System.out.println(tf.trace());
            tf.thrownException().printStackTrace();
        }
        
        while(tr.failures().hasMoreElements())
        {
            TestFailure tf  = tr.failures().nextElement();
            
            System.out.println(tf.failedTest().toString() + " failed");
        }
        
    }
    
    public void runTests() throws Exception
    {
        for(TestBase test: tests)
        {
            TestResult tr = runTest(test);
            this.printResults(tr);
        }
    }
    
    public static void main(String[] args) throws Exception
    {
        NewApproach na = new NewApproach();
        na.loadTests();
        na.runTests();
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to