java.lang.NoSuchMethodException on launching UITestCasCommon

WindowTester allows you to easily create and run unit tests for every GUI they build. It can also be used to generate system level tests.

Moderators: gnebling, Eric Clayberg, Dan Rubel, keertip, Phil Quitslund

java.lang.NoSuchMethodException on launching UITestCasCommon

Postby ajbetz » Fri Jan 28, 2011 7:09 pm

I am writing a WindowTester Pro "test runner" utility that allows me to invoke my tests, but without having to pass concrete variables about the plug-in and class names of the test suite to the command line (My application has very tight controls about command line parameters, see my earlier post: http://forums.instantiations.com/viewtopic.php?f=5&t=5664&p=18472&hilit=framework#p18472).

I am writing a plug-in that extends the org.eclipse.ui.startup extension point, so that I can invoke my activator class as soon as my Eclipse workbench finishes initialization and starts up. My test plug-in name and class name of the test I want to launch are passed as vmargs; my activator class then parses out the vmargs, and starts up the testcase.

This is where I have some questions ... I am encountering a java.lang.NoSuchMethodException when I invoke the UITestCaseCommon.run() method on the loaded class:

java.lang.NoSuchMethodException: com.ibm.sample.sampleIMTests.main([Ljava.lang.String;)
at java.lang.Class.throwNoSuchMethodException(Class.java:283)
at java.lang.Class.getMethod(Class.java:825)
at com.windowtester.internal.runtime.junit.core.launcher.LauncherFactory$MainRunner$1.run(LauncherFactory.java:113)
at com.windowtester.internal.runtime.junit.core.launcher.LauncherFactory$SeparateThreadLauncher$1.run(LauncherFactory.java:90)
at java.lang.Thread.run(Thread.java:736)


Here is the invoking code:

Code: Select all
public static TestResult runTestcase(final UITestCaseCommon testcase) throws Exception {
      try {
         final Object[] testResultObject = new Object[1]; //Container for our test result.
         
         /*
          * This little block of code is grabbing the currently running UI thread, and defining a new section of
          * code to be invoked by this thread at the next possible opportunity (polite!). The thread that invokes
          * this method will be deposed until the newly defined runnable method has finished execution. A Junit
          * TestResult is saved during th execution of this test case.
          */
         PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
            @Override
            public void run() {
               TestResult result = new TestResult();
               testcase.run(result); //Runs the test case, collects the result.
               testResultObject[0] = result;
            }//end run() method
         }); //end syncExec() method
         
         return (TestResult) testResultObject[0]; //returns our testResult
      }catch (Exception e) {
         throw new Exception(MessageFormat.format("Exception occured while running WindowTester Pro testcase {0}",
               new Object[] {testcase.getName()}),
               e);
      } // end try-catch block
   } //end runTestcase() method


I'm guessing the problem isn't so much with this piece of code, it has to do with where I create this UITestCaseCommon object:

Code: Select all
//Must present a plug-in Name and class name
               if((vmargPluginName != null) && (vmargClassNames != null)) {
                  if(!vmargPluginName.equals(EMPTY_STRING)) {
                     Bundle bundle = Platform.getBundle(vmargPluginName);
                     
                     if(bundle != null) {
                        Class<?> mainTestSuite;
                        try {
                           mainTestSuite = bundle.loadClass(vmargClassNames);
                        }catch(ClassNotFoundException cnfe) {
                           cnfe.printStackTrace();
                           
                           return new Status(Status.ERROR,
                                 Activator.getDefault().getBundle().getSymbolicName(),
                                 IStatus.OK,
                                 MessageFormat.format("ClassNotFoundException occurred when loading test plug-in {0}: " +
                                       "Could not find class {1}", new Object[]{vmargPluginName, vmargClassNames}),
                                       cnfe);
                        } //end try-catch block
                        
                        //OK ... assuming that the plug-in was found in the platform, AND this platform was able
                        //to load the main test suite class without throwing either a ClassNotFoundException
                        //or any other exception, then we can get on with the rest of the test.
                        if(mainTestSuite != null) {
                           
                           //Creates the UITestcaseCommon Artifact
                           UITestCaseCommon uiTestCase = new UITestCaseCommon(mainTestSuite) {
                              @Override
                              protected IExecutionContext createExecutionContext() {
                                 return getExecutionContext();
                              }
                           };


I didn't know what to put underneath the createExecutionContext() method I had to override, so I left it pretty bare.

According to that error message, it looks like the run() call is looking for a method in my class called "main". Needless to say when I created my plug-in test and class, I did not have a method called main. I'm kind of confused on this to the point that I'm not sure what the proper question to ask is, but is there some kind of way that I can tell my UITestCaseCommon type which method to invoke when it "runs" ?
ajbetz
 
Posts: 17
Joined: Wed Jan 05, 2011 4:10 pm
Location: Beaverton, OR

Re: java.lang.NoSuchMethodException on launching UITestCasCo

Postby ajbetz » Mon Jan 31, 2011 10:01 am

I guess to summarize what it is I am trying to do ...

I am trying to build a test launcher utility that allows me to invoke the WindowTester Pro tests not as PDE would invoke them (because PDE passes in a bunch of command line parameters that my application rejects), but instead as an Eclipse application.

I have been checking out the com.windowtester.runtime package, but can't seem to get at these classes in the source of my utility. Are these classes protected from usage?
ajbetz
 
Posts: 17
Joined: Wed Jan 05, 2011 4:10 pm
Location: Beaverton, OR

Re: java.lang.NoSuchMethodException on launching UITestCasCo

Postby ajbetz » Mon Jan 31, 2011 1:08 pm

NVM, I solved my problem to invoke the tests! :)

Here is what I changed:

1. After re-reading the UITestCaseSWT and UITestCaseCommon constructors, the Class<?> artifact that is passed as a parameter is actually intended to serve as the IApplication launcher class, which implements "main". By executing my instance of the class, it was also looking for "main" ... not the intended behavior. Instead, I changed my code so that it wasn't even trying to cast or construct my loaded Class<?> object. Instead, it was accepting the Class<?> object as a parameter in the second thing I changed:

2. Re-wrote this function to no longer accept an object of type UITestCaseSWT, but instead of type Class<?>:

Code: Select all
public static TestResult runTestcase(final Class<?> mainTestSuite) throws Exception {
      try {
         final Object[] testResultObject = new Object[1]; //Container for our test result.
         
         /*
          * This little block of code is grabbing the currently running UI thread, and defining a new section of
          * code to be invoked by this thread at the next possible opportunity (polite!). The thread that invokes
          * this method will be deposed until the newly defined runnable method has finished execution. A Junit
          * TestResult is saved during th execution of this test case.
          */
         
         PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
            @Override
            public void run() {
               TestResult result = new TestResult();
               Test test = new TestSuite(mainTestSuite);
               test.run(result); //Runs the test case, collects the result.
               testResultObject[0] = result;
            }//end run() method
         }); //end syncExec() method
         
         return (TestResult) testResultObject[0]; //returns our testResult
      }catch (Exception e) {
         throw new Exception(MessageFormat.format("Exception occured while running WindowTester Pro testcase {0}",
               new Object[] {mainTestSuite.getName()}),
               e);
      } // end try-catch block
   } //end runTestcase() method


This will invoke my tests as I expected them to.

So in case anyone else was wondering about it ... I got it figured out!
ajbetz
 
Posts: 17
Joined: Wed Jan 05, 2011 4:10 pm
Location: Beaverton, OR

Re: java.lang.NoSuchMethodException on launching UITestCasCo

Postby keertip » Wed Feb 02, 2011 8:28 am

Great! Glad that you got it all figured out. Thanks for posting the solution.
keertip
Moderator
 
Posts: 221
Joined: Thu Mar 15, 2007 10:26 am


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest

cron