Forum Discussion

Kenzo's avatar
Kenzo
Occasional Contributor
17 years ago

write junit test in groovy script...

Hi there,

I have the following piece of code which is a junit test class to test a web page:

import junit.framework.*;
import com.thoughtworks.selenium.*;
import junit.textui.TestRunner;

public class Temp extends TestCase {
    private Selenium browser;
   
    public Temp(String name) {
    super(name);
    }
   
    public void setUp() {
        //some code
    }
   
    public static TestSuite suite() {
    return new TestSuite(Temp.class);
    }
   
    public void test1(){
        // some code
}
    public void tearDown() {
        // some code
    }
   
    public static void main(String[] args){
        Temp test = new Temp("test");
    TestRunner a = new TestRunner();
    TestResult result = a.run(test.suite());
    }
}

This works fine in eclipse but in groovy i get the error :

groovy.lang.GroovyRuntimeException: Failed to create Script instance for class: class Temp. Reason: java.lang.InstantiationException: Temp

why can't i instantiate the Temp class in groovy?
Any idea on how to work around this?

thanks,

4 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    this could be because soapUI is evaluating your script as a "scriptlet" and not a class.. try the following instead:

    import junit.framework.*;
    import com.thoughtworks.selenium.*;
    import junit.textui.TestRunner;

    public class Temp extends TestCase {
        private Selenium browser;
     
        public Temp(String name) {
          super(name);
        }
     
        public void setUp() {
            //some code
        }
     
        public static TestSuite suite() {
          return new TestSuite(Temp.class);
        }
     
        public void test1(){
            // some code
    }
        public void tearDown() {
            // some code
        }
     
       
    }

    Temp test = new Temp("test");
    TestRunner a = new TestRunner();
    TestResult result = a.run(test.suite());


    If this doesn't work, you will probably need to put the Temp class in an external jar (or the script library if you are using soapUI Pro) to use it like this.

    regards!

    /Ole
    eviware.com
  • mdvijay's avatar
    mdvijay
    New Contributor
    Hi,
    I want to use selenium test integrated to SOAP UI test, can you suggest me some ideas.
    My requirement is as below
    1) do some changes in the web serivce
    2) open a browser and check for the corresponding changes in the website

    for the step 1 i can easily automate with SOAP UI, wheres to check the step 2 which opens the browser and do some testing using selenium
    can u help me some examples (selenium tests in groovy)

    Thank you

    Regards
    Vijay