&是什么QUOT;方法... ClassInitialize有签名错误..."意思? [英] What does "Method ...ClassInitialize has wrong signature ..." mean?

查看:416
本文介绍了&是什么QUOT;方法... ClassInitialize有签名错误..."意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Visual Studio 2012解决方案,我有单元测试C ++ / CLI代码,如:

In my Visual Studio 2012 solution I have a C# project for unit testing C++/CLI code, e.g.

...
using System.IO;
using Stuff;

namespace MyCLIClassTest
{
    [TestClass]
    public class MyCLIClassTest
    {
        public MyCLIClassTest() {}

        [ClassInitialize]
        public static void Setup(TestContext testContext) 
        {
        }

        [TestMethod]
        public void LibraryAccessTest()
        {
            ...
        }
    }
}

现在,C#的测试都失败,这样的消息方法MyCLIClassTest.MyCLIClassTest.ClassInitialize有误的签名。该方法必须是静态的,公开的,不返回值,应该采取类型的TestContext的一个参数。

Now, the C# tests all fail with a message like "Method MyCLIClassTest.MyCLIClassTest.ClassInitialize has wrong signature. The method must be static, public, does not return a value and should take a single parameter of type TestContext."

删除ClassInitializer后,我得到无法设置的TestContext属性的类MyCLIClassTest.MyCLIClassTest错误:System.ArgumentException:类型'对象Microsoft.VisualStudio.TestPlatform.MSTestFramework .TestContextImplementation无法转换为类型Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'..

After removing the ClassInitializer I got "Unable to set TestContext property for the class MyCLIClassTest.MyCLIClassTest. Error: System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestPlatform.MSTestFramework.TestContextImplementation' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'..

推荐答案

我使用的DLL旧的单元测试框架的版本。发生这种情况是因为,该项目近期迁移到VS2012。

I used DLLs of older unit testing framework versions. This happened because the project migrated recently to VS2012.

因此,在测试项目中Solution Explorer中找到参考。右键单击它并选择添加引用...打开参考管理器。搜索单元测试,检查版本号为10.1.0.0的Microsoft.VisualStudio.QualityTools.UnitTestFramework。取消选中该组件的所有其他版本。单击确定关闭经理。

So, in the solution explorer under the test project you find "References". Right click it and select "Add reference..." to open the Reference Manager. Search for "unittest" and check the Microsoft.VisualStudio.QualityTools.UnitTestFramework with version number 10.1.0.0. Un-check all other versions of this assembly. Close the manager by clicking OK.

这篇关于&是什么QUOT;方法... ClassInitialize有签名错误..."意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆