Two test projects with test classes as link in second project - error 'In attempting to load {...} from {...} it was determined that a test ...'
-
Friday, August 24, 2012 9:22 AM
Hi all,
Here it's my issue: I have two test projects, one called MyComp.Tests, and the other one called MyComp.WebHost.Tests; this is because in my project I have some web-service methods that I want to test directly and also through a web-service client.
In order not to have duplicate test method helpers, I've added the test units files from MyComp.Tests to MyComp.WebHost.Tests as links (Add existing item -> Add as link). After that I've inherited MyComp.Tests.SomeUnitTest class as MyComp.WebHost.Tests.SomeUnitTestWithWebService, and added to it only the functionality to test with web-service client.
When recompiling the entire solution, I receive the error: In attempting to load SomeUnitTestMethod from MyComp.WebHost.Tests.dll it was determined that a test with the same id named SomeUnitTestMethod in MyComp.Tests.dll already exists in the catalog.
The message says well what it says, but I don't know what approach to take on this matter. What would you suggest ?
Thanks in advance.P.S.: A similar post can be found at http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/8d82d23e-3f2c-41d7-a1ef-d8dd1fd677ee/ but it doesn't respond to my exact question.
All Replies
-
Monday, August 27, 2012 2:18 AMModerator
Hi Ghiutzu,
Thank you for posting in the MSDN forum.
I would like to know if you compile each project in the same modes: Debug or Release. If you don’t, you can try to clean solutions in both modes, and then rebuild in the mode you want.
In addition, I would like to know what kind of editions of Visual Studio you used, because I don’t find the Add as link after Add existing item. And whether the units test files added into MyComp.WebHost.Tests project are in the project root or not. If not, move them to the project root.
Best regards,
Amanda Zhu [MSFT]
MSDN Community Support | Feedback to us
-
Monday, August 27, 2012 7:28 AM
Hi Amanda,
I compile all my project in the solution in Debug mode.
Also, I'm using Visual Studio 2010 Premium.
I used "Add as link" feature by right-click-ing on the test project, choosing "Add" -> "Existing item..."; after that, from "Add Existing Item" popup window, I navigate to the first test project, choose the initial test class, and from the "Add" button, I click the drop-down arrow found on the "Add" button, which will show me to options: "Add" and "Add As Link".
My unit test files are not in the root folder, indeed. I've moved the test units from MyComp.WebHost.Tests to the root folder, but I still get the same error message. The initial tests from MyComp.Tests also have a special folder structure.
As a note, we have a predefined folder structure that we must follow for unit tests, depending on our business logic model structure; I could duplicate the code from the first unit test project, and not "add as link" the test classes (therefore not havintg duplicate test Id), but I was initially thinking that this functionality should work...
If you know an alternative for not having duplicate code, please let me know
Thanks for your answer and best regrds.
- Edited by Ghiutzu Pop Monday, August 27, 2012 7:31 AM
- Edited by Ghiutzu Pop Monday, August 27, 2012 7:40 AM
- Edited by Ghiutzu Pop Monday, August 27, 2012 7:43 AM
-
Monday, August 27, 2012 2:37 PMModerator
Hello Ghiutzu,
If you want to get some methods of MyComp.Tests.SomeUnitTest class in MyComp.WebHost.Tests project not for having duplicate code, you can let a class inherit Some
UnitTest class. Classes can inherit from another class. The new class—the derived class—then gains all the non-private data and behavior of the base class in addition
to any other data or behaviors it defines for itself .
You can do the following steps :
1.Right click MyComp.WebHost.Tests project and select Add reference.
2.In the pop up window, select the MyComp. Tests project in the Projects module
and add.
3.Add "using MyComp.Tests" namespace in the test class to let the added project
found and inherit SomeUnitTest class like this class B : A.
I hope this will help you.
Best regards,
Amanda Zhu [MSFT]
MSDN Community Support | Feedback to us
-
Tuesday, August 28, 2012 7:20 AM
Hi Amanda,
Thanks for your answer.
I forgot to mention that another constraint we must follow is not to reference the first test project from the second test project. Sorry about that :( , I should have specified it in the first place.
Best regards,
Ghiutzu
-
Wednesday, August 29, 2012 7:39 AM
You can try same linked file with different conditional namespaces e.g.
#if Pr1 namespace TestProject4 #else namespace TestProject1 #endif { [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { } } }
Then define Pr1 macro in one of the project properties (Project -> <projectName> Properties... -> Build -> Conditional compilation symbols)That way both project will have same code (linked file) just with different name space. That will not cause the issue duplicate id.
Regards,
Vikram Agrawal,
Developer, VSTLM, Microsoft Corporation- Edited by Vikram Agrawal Wednesday, August 29, 2012 7:39 AM
- Proposed As Answer by Vikram Agrawal Thursday, August 30, 2012 12:44 AM
- Marked As Answer by Amanda ZhuMicrosoft Contingent Staff, Moderator Thursday, August 30, 2012 3:59 AM
-
Thursday, August 30, 2012 7:24 AM
Hi Vikram,
Thanks for your answer, that seems the right way to do it, I'll give it a try.
Another approach that we'll be testing is to use a separate helper class to be used by both test projects, in the second project added as a link (the helper class will do all the necessary initializations and configurations).
Best regards,
Ghiutzu

