无法在单元测试中执行负载测试 [英] Not able to perform Load test on unit tests

查看:85
本文介绍了无法在单元测试中执行负载测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试使用Visual Studio 2017对单元测试执行负载测试,但它给我一个错误 


无法为UnitTestProject1.UnitTest1类设置TestContext属性。错误:System.ArgumentException:类型为'Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext'的对象无法转换为类型'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'


My单元测试看起来像这样


            

名称空间UnitTestProject1

{

    [TestClass]

   公共类UnitTest1

    {

        private TestContext textContext;



        public TestContext TestContext

        {

            get {return textContext; }¥b $ b            set {textContext = value; }¥b $ b        }¥b $ b        [TestMethod]

        public void TestMethod1()

        {

$


        }¥b $ b    } b $ b}


我观察到当我删除所有测试上下文的东西时,我能够成功运行负载测试。


是不是可以在Visual Studio 2017中使用TestContext参数运行负载测试?



谢谢,


Joshi


解决方案

嗨Joshi,


我在Visual Studio 2015和Visual Studio 2017中测试的原始帖子中的示例代码。我只在TestMethod()中添加Assert.AreEqual()方法。它工作正常。


根据错误消息,您正在尝试将Unit.UnitTestAdapterContext转换为UnitTesting.TestContext。它们是不同的类型,这就是转换失败的原因。请检查TestMethod中的代码,是否有任何赋值语句
为TestContext设置了错误的值类型。


如果可能,请分享一些关于TestMethod的代码片段帮助我们重现这个问题。它可以让我们帮助您找到代码中的问题。


最好的问候,

Weiwei


Hi,

I am trying to perform load tests on the unit tests using Visual studio 2017, but it is throwing me an error 

Unable to set TestContext property for the class UnitTestProject1.UnitTest1. Error: System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'

My unit test looks like this

            

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        private TestContext textContext;

        public TestContext TestContext
        {
            get { return textContext; }
            set { textContext = value; }
        }
        [TestMethod]
        public void TestMethod1()
        {


        }
    }
}

I have observed that when i removed all test context stuff, then i am able to run the load test successfully.

Is it not possible to run the load test with TestContext paramenter in visual studio 2017?

Thanks,

Joshi

解决方案

Hi Joshi,

The sample code in your original post I have tested in both of my Visual Studio 2015 and Visual Studio 2017. I only add a Assert.AreEqual() method in my TestMethod(). It works fine.

According to the error message, you are trying convert a Unit.UnitTestAdapterContext to UnitTesting.TestContext. They are different type, this is why the convert is failed. Please check the code in your TestMethod, whether there has any assignment statement for TestContext is set a wrong type of value.

If possible, please share some code snippet about the TestMethod to help us reproduce this problem. It could let us help you find out the problem in your code.

Best Regards,
Weiwei


这篇关于无法在单元测试中执行负载测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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