CppUnit development mailing list wrote:
> Hi cppunit developers and users!
>
> I have a question about test execution. I have a test suit as shown
> below with two test methods. The code is then compiled into a dll
> and I run it with this command:
>
> DllPlugInTesterd_dll.exe -c plugin_d.dll
>
> I now have the following problem. During startup cppunit creates two
> instances of the ExampleTest class. Then it calls setup(),
> sampleTest()
> and finally teardown(). Then it does the same on the second instance
> with the method sampleTest2().
Each test case has its own instance to ensure each test case execution is
independent.
> This looks quite strange. I thought I could initialize some class in
> the setup method which is then shared between all the different test
> method calls?
>
> The reason why I would like to share an instance between them is that
> I
> have to start an external program during test execution (which takes
> very long and therefore should not be started and killed for each test
> method invocation). I therefore used a shared pointer which I thought
> would be accessible for all test invocations. But since each
> invocation
> uses a different instance this does not work.
Possible solutions I see are:
- make a single test case and add log to know which "internal" test case
failed (see ClockerPlugIn as an example to integrate a listener listener
hook with test result). Downside is you won't get precise reporting of what
failed in the results without reading the log.
- make your "shared" instance static. Though, you would still need to figure
out when to clean it up. Thinking about it, may be you could use a rough
algorithm: if last executed test did not ask for it, then destroy the shared
instance. Makes the component that managed the "shared" instance a test
listener.
Baptiste.
> Any suggestions how this should be done would be really great!
>
> Please also tell me if what I wrote / want is unclear
>
> Thanks a lot, Fabian
---
Baptiste Lepilleur <bl...@us...>
CppUnit maintainer
OpenTest and CppUnit 2 developer.
|