c# - Visual Studio 2013 Test Explorer -


i have created simple c#/.net solution 2 projects:

  • a class library.
  • a unit test project single unittest class, , have added moq project.

i created 3 unittest methods, use moq mock single class, injected class.

using system; using system.collections.generic; using microsoft.visualstudio.testtools.unittesting; using moq;  namespace mocksimple.test {     [testclass]     public class unittest1     {         [testmethod]         public void testmethod1()         {             var mock = new mock<classimplementingfunctionality>();             mock.setup(functionality => functionality.add(it.isany<int>(), it.isany<int>())).returns(4);             var classundertest = new classundertest(mock.object);             classundertest.method(2,2);             mock.verify(m => m.add(it.isany<int>(), it.isany<int>()), times.exactly(1));         }          [testmethod]         [expectedexception(typeof(argumentexception))]         public void testmethod2()         {             var mock = new mock<classimplementingfunctionality>();             mock.setup(functionality => functionality.add(it.isany<int>(), it.isany<int>())).returns(0);             var classundertest = new classundertest(mock.object);             classundertest.method(10,5);         }          [testmethod]         public void testmethod3()         {             var ints = new list<int> {1, 2, 3, 4};             var mock = new mock<classimplementingfunctionality>();             mock.setup(functionality => functionality.add(it.isany<int>(), it.isany<int>())).returns(4);             var classundertest = new classundertest(mock.object);             classundertest.loopints(ints);             mock.verify(m => m.add(it.isany<int>(), it.isany<int>()), times.exactly(ints.count));         }          [testmethod]         public void testmethod4()         {             var ints = new list<int> { 1, 2, 3, 4, -5, -2, -7 };             var mock = new mock<classimplementingfunctionality>();             mock.setup(functionality => functionality.add(it.isany<int>(), it.isany<int>())).returns(4);             var classundertest = new classundertest(mock.object);             classundertest.loopints(ints);             mock.verify(m => m.add(it.isany<int>(), it.isany<int>()), times.exactly(4));         }      } } 

but when trying run test methods using builtin test-manager in vs2013, following error in the test output window:

------ run test started ------ composition produced single composition error. root cause provided below. review compositionexception.errors property more detailed information. value not fall within expected range.  resulting in: exception occurred while trying create instance of type 'microsoft.visualstudio.testwindow.model.testgroupcollection'.  resulting in: cannot activate part 'microsoft.visualstudio.testwindow.model.testgroupcollection'.  element: 'microsoft.visualstudio.testwindow.model.testgroupcollection' -->  microsoft.visualstudio.testwindow.model.testgroupcollection  resulting in: cannot export 'microsoft.visualstudio.testwindow.model.testgroupcollection (contractname="microsoft.visualstudio.testwindow.model.testgroupcollection")' part 'microsoft.visualstudio.testwindow.model.testgroupcollection'.  element: microsoft.visualstudio.testwindow.model.testgroupcollection (contractname="microsoft.visualstudio.testwindow.model.testgroupcollection") -->  microsoft.visualstudio.testwindow.model.testgroupcollection  ========== run test finished: 4 run (0:00:00,3464634) ==========*  

i can run test-methods using resharper unit test framework.

for me looks mstest trying dependency injection or looking either mef or unity configuration.

any ideas?

graci, graci...

in developer command prompt run devenv /rootsuffix exp

the command above solved problem :-)


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -