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" ?