Click here to Skip to main content
15,885,660 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hello!!!

I am having a source code with a solution having 25 projects!!. So, it is having both C# and managed c++ code also. i need to test one of the C# project calls. but this project is of type "Window application"(Not DLL). Even though it is windows application, my requirement is to call only few internal functional calls (Not related to windows form). Now i need to create a separate C# test project to call these functionality. is it possible to do it like this? can any one suggest a way or examples? And one more thing, i don't have any freedom to modify the existing source code.

Thanks in advance.
Posted
Comments
V. 17-Feb-14 8:57am    
I never did it, but an ex-colleague did. Apparently you need to use managed C++ as an interface between the unmanaged code and the managed code. They can't talk directly to each other.

Another thing you could do is make those calls "public" so they can be accessed with dynamic binding. (hope I'm explaining this correctly) Then you can use those function with a DllImport attribute. http://msdn.microsoft.com/en-us/library/aa984739(v=vs.71).aspx

I'm pretty sure there is an article about this topic.
Sergey Alexandrovich Kryukov 17-Feb-14 12:19pm    
You are trying to present thing as more complex than they are. OP does not have unmanaged code.
Please see my answer to this question.
—SA
agent_kruger 18-Feb-14 23:51pm    
sorry sir, but do you want to run a particular project in the solution.

1 solution

It looks like you are aiming to develop unit testing for your solution(s), which is a good thing. It can be done in many different ways.
First of all, please read: http://en.wikipedia.org/wiki/Unit_testing[^].

First of all, you can create and add some test projects. Even though there are universal unit testing techniques which don't require creation of any application-specific test projects (please see below), other types of testing and the whole development strategy may require them, so I'll give you some idea. Besides, it's a good idea to have some prototype projects.

So, it looks like testing some EXE seems to be a problem for you. Here, you should understand one simple thing: you can reference EXE (or any kinds of assemblies for that matter), exactly as DLLs. Essentially, for .NET, there are no EXEs and DLLs, there are just assembly. Any of those assemblies can be referenced by some test-project assembly. Now, a little problem is: if you use some types/members internally for the assembly, you should give them internal access specifiers, but using them from a referencing assembly required public. That said: 1) you can create special tests inside the assembly under the test and make them public, probably conditionally (depending on #define preprocessor conditions), or 2) you can use Reflection in your test projects, as Reflection can work regardless of access specifiers. As Reflection approach is more difficult, you may consider using some existing unit testing facility.

For a 3rd-party testing facility, I would recommend open-source NUnit:
http://en.wikipedia.org/wiki/NUnit[^],
http://www.nunit.org/[^].

Your problem is greatly simplified by the fact that you only test .NET project. C++/CLI and C# project practically don't have any barriers between them. You can consider other facilities. Please see this list:
http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#.NET_programming_languages[^].

Basically, you create only the tests, which can be marked by special attributes. The utility finds the tests and perform testing automatically. It's your responsibility to provide a test set which is fairly comprehensive. And don't forget: testing along will never guarantee the correctness of your software.

—SA
 
Share this answer
 
Comments
Andrius Leonavicius 17-Feb-14 12:45pm    
+5, nice answer.
Sergey Alexandrovich Kryukov 17-Feb-14 12:48pm    
Thank you Andrius.
—SA
Maciej Los 17-Feb-14 18:16pm    
Well explained!
+5
Sergey Alexandrovich Kryukov 17-Feb-14 18:33pm    
Thank you, Maciej.
—SA
Lakamraju Raghuram 17-Feb-14 22:33pm    
The OP said: " i don't have any freedom to modify the existing source code."

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