Phlip said:
CppUnit and its ilk can be used for QA testing, but that's not what we've
been discussing. We are discussing TDD, where we write tests that help force
our lines of code to exist. This helps to refactor our designs as they grow.
That is specifically what I talk about.
Hiding the MT nature of a service does not help you design it properly !
If your interface design is inherently MT then show me how to use it in
an MT environment, otherwise I can't evaluate how well it works.
If we are not writing a kernel, we don't need to TDD its event systems. We
won't refactor our kernel, so gaps in our test coverage are very low risk.
I disagree. I think this is why I have seen so many abortions of MT
code, because they don't take into account the big 3:
1. resource deadlock (not just mutexes)
2. reliable destruction
3. reliable event management
There are API's I have come across (WININET is one) that you cannot
close properly.
Also, you cannot return a handle from an MT call, it must be made
available to the caller *before* you return.
The point is, of the few classes where asynchronism is critical, you
cannot design it properly unless you take into account the MT nature of
the interface. If you think you can, then show me.
So you can safely rely on a policy "wait till we have a bug there". (Note
this is the policy that test-free programs already follow - for everything!)
After I'm done writing the code, I usually write at least one stress
test which usually finds a couple of bugs and occasionally bugs in the
interface itself.
TEST_(TestDialog, SetTimer)
{
CButton slowButton = m_aDlg.GetDlgItem(IDC_SLOW_OPERATION);
slowButton.SendMessage(BM_CLICK);
BOOL thereWasaTimerToKill = m_aDlg.KillTimer(0);
CPPUNIT_ASSERT(thereWasaTimerToKill);
}
Not a very useful timer interface, how can I reset the timer ? Can I
safely delete my client and see the timer get deregistered
automatically? Can I set the timer to an absolute time or an interval?
I'd like an interface that is as independent as possible of the O.S.
interfaces since it's a fundamental too.
Compare it to the Austria C++ timer test and I think you'll see what I mean.
I'm aware that doesn't answer the exact question, but I already had this
answer available!
The point is, you can't design something using TDD if you don't show how
it's done. If your interface is dealing with MT issues, there really is
little point in not doing an MT unit test for the purposes on TDD.