How to use IoC container for unit testing
-
23 กุมภาพันธ์ 2555 11:57
Hi there,
I am new to unit testing. I read an article about unit testing recently.
It is said that "... Problems can arise from using constructors to inject implementations. If your code under test requires more than one stub to work correctly without dependencies, adding more and more constructors (or more and more constructor parameters) becomes a hassle, ...".
It is also said that the IoC container can solve this problem.
As far as I know, constructor injection is the third type of IoC.
I want to know about the IoC container. How it works and how it solves the problem of constructor injection while unit testing.
I got a implementation of the IoC container in C++ from this blog: http://www.codinginlondon.com/2009/05/cheap-ioc-in-native-c.html
However, I don't get the concept yet.
Does anyone have good sample code of the IoC container and sample code of how this container solve the unit testing problem?
Thanks in advance.
- ย้ายโดย Helen Zhao 27 กุมภาพันธ์ 2555 3:40 (From:Visual C++ General)
ตอบทั้งหมด
-
27 กุมภาพันธ์ 2555 3:39
Hi JupiterLee,
According to your descriprion, I'd like to move this thread to "Visual Studio Unit Testing Forum" for better support, where more experts live.
Thanks for your understanding.
Best regards,Helen Zhao [MSFT]
MSDN Community Support | Feedback to us
-
27 กุมภาพันธ์ 2555 6:57ผู้ดูแล
Hi JupiterLee,
Thank you for posting in the MSDN forum.
Do you mean that you are using Visual Studio Unit Testing for a method with the IoC container? Can you share us the document or the link about:
"... Problems can arise from using constructors to inject implementations. If your code under test requires more than one stub to work correctly without dependencies, adding more and more constructors (or more and more constructor parameters) becomes a hassle, ...".
I didn’t use the IoC container before, but I did some research about this issue, and I found some articles about the IoC container in unit test projects, see
http://stackoverflow.com/questions/1465849/using-ioc-for-unit-testing
A Video about Getting Started With Unit Testing (Dependency Injection, IoC Containers, Unity, Moq).
Hope it can provide useful information.
Best Regards,
Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
- ทำเครื่องหมายเป็นคำตอบโดย Jack Zhai - MSFTMicrosoft, Moderator 5 มีนาคม 2555 1:45
-
29 กุมภาพันธ์ 2555 6:08ผู้ดูแล
Hi JupiterLee,
I am writing to check the status of the issue on your side. What about this problem now? Would you mind letting us know the result of the suggestion? If no help, please let us know the latest news about this issue.
Thank you for your understanding!
Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
-
6 มีนาคม 2555 3:08Thanks for moving this thread to correct forum
-
6 มีนาคม 2555 3:14
Hi Jack,
Thanks for your help.
I am studying on those articles, and it might take some time.
Those articles are helpful.