Programmer never feels boring

One of my friends complained about not having enough workload to fill up her powerful work engine. Well, that’s truely a problem if there are nothing to do for some people. I am among those who hate to be in a daze for killing time. But fortunately, I am a programmer. I could easily spend hours in writing some code and improving them, or even come up with some changes to start evolving to the code if it’s not exciting enough. Different professionals have different way to keep their blade sharp: a project manager need a project, a negotiator need a opponent, a mathematician need a problem. For me for now, I’like to start from writing unit test for my code:)

It seems good for being a programmer, but does programmer has lots of time to kill?

OK, let’s stop dreaming, because we are all busy professionals:)

Digg This
Advertisements

Use Guice in test? why not?

I’ve actually asked the similar question some days before, when I was trying to test a singleton object implemented by @Singleton anotation.  Yes, I agree with the answer that I should only concentrate on the functionality of the class itself, not the singleton charactor, in the unit test. It’s the reponsibilty of the unit test of Guice to prove the class that mark with @Singleton will have only one instance, we don’t need to reinvent the wheels.

But, is Guice really not nessesary for the unit test? I doubt it, after more and more applied Guice into my project. When we totally depend on Guice for the object creation, every object in our code is dependency injected. This means if you want to test a class that have 3 dependencies, you should have to write at least 3 lines before you could be able to instanciate the object, not include the dependency of the dependencies. No one like to write 10 lines of test code for a method of 5 lines of code, right? Guice is doing great in helping us to write production code, and it could do the same to help us write test code. This might bring some worrry, will Guice break the isolation of the unit test? Will other object get affected by running one test? We don’t like get our menoy gone after launche a test of Tansaction class anyway. Don’t worry, Module will help. You could easily replace a faked object with the real one using Guice, by only define a new module contains one line like this:

bind(Transaction.class).with(FakedTransactionImpl.class);

Digg This