[Dev] Session by Name
William Martinez Pomares
wmartinez at AVANTICATEC.NET
Thu Apr 19 09:26:57 PDT 2007
Hello.
In the discussion, the need to keep a "session" in a testcase came up.
What does this mean?
When a run is executed and ended, the next run in the same test will not
keep any instances or values from the first one. If you are executing,
for example, a several step transaction in http and thus need to keep
the same http client instance alive between each run, you are in
trouble.
One solution, already implemented and tested, is to keep the instances
in the "session" alive while there are runs with the same name. See the
example below:
<usecases>
<usecase name="INSERT">
<sequence name="inserts" proportion="100">
<test>
<run name="sum1" testclass="Cumulative"
method="cumulate" langtype="java">
<argument name="add" value="6" />
</run>
<run name="sum1" testclass="Cumulative"
method="cumulate" langtype="java">
<argument name="add" value="10" />
</run>
<run name="sum2" testclass="Cumulative"
method="cumulate" langtype="java">
<argument name="add" value="6" />
</run>
<run name="sum2" testclass="Cumulative"
method="cumulate" langtype="java">
<argument name="add" value="50" />
</run>
<run name="sum2" testclass="Cumulative"
method="cumulate" langtype="java">
<argument name="add" value="60" />
</run>
<run name="sum2" testclass="Cumulative"
method="reset" langtype="java" />
</test>
</sequence>
</usecase>
</usecases>
Note there are two blocks of runs with different name each (sum1 and
sum2). Each one will represent a session. Class Cumulative will be
instantiated in the first sum1 run, in the next one, it will continue
with the same intance (keeping the accumulated value) and will start to
add 10. For the third run, since its name changed to sum2, it will
create a new cumulate instance, thus creating a new session.
As you know, the run sequences are not more that just unit tests, which
should be independent. Thus, the semantics of sessions in the usecase at
unit test level may not fit, but here we are working with usecases. What
do you think of the solution? Comments? Improvements? Readability?
William.
More information about the Dev
mailing list