|
|
Re: Are SuiteRunner tests tied to Java Methods
|
Posted: Feb 28, 2003 2:21 PM
|
|
I'm glad you asked your question. Even though you said you figured out a solution, I want to post an answer for others to read.
Basically, a Suite, an object that represents the conceptual notion of a suite of tests, is responsible for executing itself. To get a Suite to execute, you invoke its execute method. The default behavior of execute, i.e., the implementation of Suite.execute, is to call executeTestMethods and executeSubSuites, in that order. The default behavior of executeTestMethods is to discover test methods on itself via reflection, and invoke them. The default behavior of executeSubSuites is to invoke execute sequentially on each of this Suite's sub-Suites.
The most common way to create a test suite with Artima SuiteRunner, is to create a subclass of Suite and define test methods. However, you can also override the execute methods described above in your Suite subclass. For example, if you want to run test methods in a particular order, you can override executeTestMethods and make sure the test methods are invoked in your preferred order.
In your case, you want to create a conceptual suite of tests that is composed of the same test functionality called with different data values read from an XML file. There are several ways to do that with Artima SuiteRunner, but here's the way I would first think of doing it. Create a subclass of Suite. Define a test method that accepts the appropriate test data as a parameter.
Then, override the execute method, which takes a Reporter. Your execute method would open the XML file and read in the data. For each piece of data, call Reporter.testStarting, and invoke your test method with the appropriate value for the test data. If the test method returns normally, invoke reporter.testSucceeded. If the test method completes abruptly with an exception, invoke reporter.testFailed. And you probably want to close the XML file in a finally clause.
If you also want to have sub-Suites, you could override executeTestMethods instead of execute itself and implement it in the same I described above for overriding execute.
Basically, you want to create a conceptual suite of tests that behaves slightly differently than the default behavior provided by Suite itself. It was our intent that you be able to do that by customizing the behavior of the execute methods, execute, executeTestMethods, and executeSubSuites. So that's the way I would recommend doing it.
|
|