Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am learning unit testing and was requesting a sample c# code for the project https://github.com/alialavia/MSINet which will guide me on what to do.

What I have tried:

stilll can't determine which methods to include in test and which to leave out.
Posted
Updated 18-May-17 4:32am
Comments
F-ES Sitecore 18-May-17 6:49am    
That code can't be unit tested, it is mainly static methods and no abstraction to decouple the code\logic from external dependencies such as msi.dll.
Member 11239384 18-May-17 6:59am    
i meant the project.not the code example given.
F-ES Sitecore 18-May-17 7:07am    
I was talking about the project (the one in github)
Member 11239384 18-May-17 7:12am    
have you opened in visual studio?what about enumerate() in installproprty class.can't u test it
F-ES Sitecore 18-May-17 7:28am    
You can't test it because it calls MSI.EnumerateGUIDs which has a reliance on msi.dll and will enumerate the installed products on whatever PC it is on. Unit tests test logic and need to be self-contained. The only logic in that code is that a function called EnumerateGUIDs which is barely worth testing. It's also impossible to know what the method has done because you can't inject your own services\data into the class as it hasn't been written in a way that supports it. You can't test the results as what is the outcome? The outcome will vary on every machine it is ran on. Finally any enviornment you run those tests on will need msi.dll installed and working with consideration taken for the user account running the tests.

Have you already watched tutorials on main unit testing frameworks?
For example
MSDN: Walkthrough: Creating and Running Unit Tests for Managed Code[^]
MSDN: Unit Test Basics[^]
CodeProject: Creating Unit tests for your c# code[^]
NUnit - QuickStart[^]

It may be wiser to start from the beginning with existing learning material than to pick up a random project which, as it has been said, is not really testable.
 
Share this answer
 
There isn't a single method in that project that is unit testable in any practical sense. The entire project would need to be rewritten to accommodate testing.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900