Reputation: 6833
I am a beginner to JUnit and design patterns, so please pardon me.
I was reading this technical webpage:
I can understand the actual coding and class organization etc. The only thing that confuses me are the two questions below related to this particular problem:
It used a design pattern called "dependency injection" by using Google's Guice, however, I found that I could get around without using this design pattern achieving the same function. I wonder using dependency injection is not a must in this problem?
Since I am new to JUnit, my understanding is that he wrote test cases for cart,item and test them individually to prove the correctness. But why does he need the final "Build and Deployment" section to compile and run the test program, since I can easily do that without creating that xml file and just do right-click in Eclipse and select "run as JUnit test".
Please give me some help on JUnit and design patterns, thank you!!
Upvotes: 1
Views: 883
Reputation: 95614
Guice is a dependency injection framework, which is a very useful tool for managing long chains of objects and their dependencies, and for changing implementations later. It is not strictly necessary for this problem, or for any problem, but you may find it very useful in certain circumstances.
new
operator and then replacing them later).The Build and Deployment section refers to a tool called Ant, which is a way of using XML to specify build instructions and dependencies such as JUnit. Eclipse has a set of built-in tools for managing the classpath and managing dependencies on JUnit, which means that you do not need to build one of those on your own. However, if you wanted to run your tests outside of Eclipse, you may need to create a file similar to that one.
You can read more about Apache Ant to see exactly what it can do for your project, and likewise read more about Google Guice and why dependency injection can be a good idea for some projects.
Upvotes: 2