From: ara.t.howard@... Date: 2007-01-04T10:15:50+09:00 Subject: Re: Problem in Unit Testing Methods that start new threads On Thu, 4 Jan 2007, Hemant Kumar wrote: > > 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. > often methods should do one of two things: - succeed or throw an exception - return a value indicating success in your case the former should be sufficient - you can assert that nothing is raised and move on. if that's not sufficient consider changing the way your method works: testing internal state is, at least, going to make maintaining your tests very very hard since they're so cozy with your impl. cheers. -a -- if you find yourself slandering anybody, first imagine that your mouth is filled with excrement. it will break you of the habit quickly enough. - the dalai lama