Writing your own tests: Sample 1
The following source code is an example of a skeleton test that returns static data. The test is given here as an example of the WMQTest interface.
/*
* Licensed Materials - Property of IBM
*
* 63H9336
* (c) Copyright IBM Corp. 2005, 2020. All Rights Reserved.
*
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with
* IBM Corp.
*/
package com.ibm.mq.explorer.tests.sample;
/**
* Sample test that is run from an additional test in the WMQ standards test tree
*/
public class WMQTestSimple extends WMQTest {
/*
* (non-Javadoc)
*
* @see com.ibm.mq.explorer.tests.WMQTest#runTest(com.ibm.mq.explorer.tests.internal.actions.WMQTestEngine,
* org.eclipse.core.runtime.IProgressMonitor, com.ibm.mq.explorer.ui.extensions.MQExtObject[],
* java.lang.String)
*/
public void runTest(WMQTestEngine callback, IProgressMonitor guimonitor,
MQExtObject[] contextObjects, TreeNode treenodeId) {
// Start with the default implementation. this will store a handle
// to the test engine that will be needed when we want to submit
// any results at the end of the test
super.runTest(callback, guimonitor, contextObjects, treenodeId);
// prepare space to store test results
ArrayList testresults = new ArrayList();
// initialise the progress bar part of the GUI used to show progress (4 stages)
guimonitor.beginTask(getTestName(), 4);
// Loop through 4 times, incrementing the progress counter by 1 each time
for (int k = 0; k < 4; k++) {
try {
// Sleep for a bit so it looks like we are doing some work
Thread.sleep(900);
}
catch (InterruptedException e) {
}
// increment GUI progress bar used to show progress, completed 1 sleep
guimonitor.worked(1);
}
// Create a new test result and add it to our array list of results
testresults.add(new WMQTestResult(IMarker.SEVERITY_INFO, "SAMPLE: Our addition test worked!", //$NON-NLS-1$
"Object name", getTestSubCategory())); //$NON-NLS-1$
// package up results and return - test complete.
testComplete((WMQTestResult[]) testresults.toArray(new WMQTestResult[testresults.size()]));
}
}