From: Hemant Kumar Date: 2007-01-04T10:08:32+09:00 Subject: Re: Problem in Unit Testing Methods that start new threads On Thu, 2007-01-04 at 06:57 +0900, Pit Capitain wrote: > Hemant Kumar schrieb: > > I have a bit of doubt, in Unit Testing Programs that start new threads. > > Please have a look at the code below: > > (...) > > Hemant, in addition to what the others said, it's not clear to me what > you really want to test: whether a new thread is started, whether the > instance variable changed after a certain amount of time, whether the > instance variable changed at the end of the new thread, ... > > I'm a fan of black box unit tests, so for me, the tests should specify > what you expect from the *interface* of the object under test. I > wouldn't test for values of certain instance variables or for threads > created internally, unless those are part of the desired interface of > your objects. > > Regards, > Pit > Agreed Pit, but basically I want to test state of my program through Unit Tests and whether each method modifies state of program as it was intended? Now, unit testing methods that return something on invocation is easy and i don't need to go around running asserts on instance variables. But I have some doubt regarding testing methods that don't return anything explicitly and rather update instance variables. Earlier, I was writing Unit Tests for a networking application which i wrote using EventMachine. Now since, EM is completely based on callbacks, you can't do a check on return values of methods. Hence I had to rely on doing asserts on instance variables. I would love to know, how do i go about unit testing in such cases. I can't yet grasp concept of code that can be unit tested easily i guess. gnufied