[interfacekit] Threaded cppunit
- From: "Jeremy Rand" <jrand@xxxxxxxx>
- To: interfacekit@xxxxxxxxxxxxx
- Date: Thu, 31 Jan 2002 01:40:14 EST
> Hi Jeremy,
>
> I was reading the README (or docs, or whatever it was) for CppUnit,
and
>it's derived from JUnit, a test suite for Java. In the notes it says
>that one of the things they left out was a threaded test case. You
>might want to take a look at the original JUnit and see what they did
>(not that I'm saying what you've done is bad at all; heck, I haven't
>looked at either version yet :)
I took a quick look at JUnit and for the life of me, I can't find much
reference to how to do threaded testing under JUnit. It does say that
the TestResult class in JUnit is synchronized (using the built in
features from the Java language itself) so it is safe to use with
multithreaded tests. However, it isn't clear to me how they are
perfoming a threaded test in Java with JUnit.
I suspect that because threads is essentially an integral part of the
Java language, they are basically getting threading support for free.
Java supplies very simple ways to start threads so they probably did
nothing special in the testing framework to support it.
Because C++ does not have that functionality, the CppUnit framework
just can't offer that flexibility. I considered two different
possibilities:
1. Model the multithreaded test as a single test which contained many
threads.
2. Model the multithreaded test as a set of tests where each thread was
a test which all ran concurrently.
I started implementing the first one, but test failures are exceptions.
If the thread does not catch the exception somewhere on the stack, it
gets lost. I tried to put in the catch blocks at the thread entry
point but I cannot easily get a pointer to the TestResult which needs
to be updated because of the exception. I considered saving a pointer
to it in the TestCase class in the run() method, but that doesn't work.
Sometimes the TestCase which calls run() is actually a TestCaller() not
the this pointer for the class performing the test.
I have settled on the second option. I don't have to worry about
propagating the TestResult to each class because the ThreadedTestSuite
does that for me. The odd thing about this is that the number of tests
reported in the result is actually = tests * threads per test. This
happens because each thread is modelled as a test. But the end result
should be OK.
Suggestions on how to improve the interface would be appreciated.
Thanks.
> Graham
--
Jeremy Rand
jrand@xxxxxxxx
Other related posts:
- » [interfacekit] Threaded cppunit