prevent vstest discovery engine locking DLLs

前端 未结 2 679
醉话见心
醉话见心 2021-02-18 16:15

I have some C# unit tests for a VS2012 project which calls a VS2010 c++ DLL using DllImport pinvoke.

As a pre-build event for the test project, I copy the latest versio

2条回答
  •  不要未来只要你来
    2021-02-18 16:34

    I had a similar problem where I created a "Test" project that didn't actually have any tests in it. (As a C++ Library developer I wanted to make sure that certain headers were able to be compiled with CLR enabled, so I made a fake CLR project to just compile them with CLR. If it compiled, it passed.) The DLL created was being held open indefinitely by the vstest.discoveryengine.

    I fixed it by adding an Ignored test to the project. I think vstest.discoveryengine will hold on to the dll until it finds all the tests in the dll, but if there are no tests to be found, then it will hold onto it forever.

    The test I added (I think it is the default test) Note the TEST_IGNORE() to make sure it isn't executed:

    #include 
    
    namespace CLRTests
    {
       TEST_CLASS(CLRTestsClass)
       {
       public:
    
          BEGIN_TEST_METHOD_ATTRIBUTE(CLRTest1)
             TEST_OWNER(L"")
             TEST_DESCRIPTION(L"")
             TEST_PRIORITY(1)
             TEST_IGNORE()
             END_TEST_METHOD_ATTRIBUTE()
             TEST_METHOD(CLRTest1)
          {
             // TODO: Your test code here
          }
    
       };
    }
    

    I hope this is possible in your situation.

提交回复
热议问题