单元测试使用非托管C ++的c#项目

时间:2012-04-02 09:50:23

标签: c# c++ visual-studio-2010 unit-testing testing

我有一个C#项目,它通过C ++ / CLI与非托管C ++交互。我做了一个单元测试,它使用了非托管C ++的所有功能并返回状态。在基本机器上运行时的单元测试没有问题并运行顺利。远程执行时,相同的单元测试失败。在远程机器上运行时,软件执行顺利。

注意:满足远程计算机中的所有依赖项

这是代码

[TestMethod()]
public void getstateTest()
{
    bool expected=true;
    bool actual=false;
    try
    {
        GUI.test target = new test();
        expected    = true; // TODO: Initialize to an appropriate value
        actual      = target.getstate();
    }
    catch (FileNotFoundException exception)
    {
        MessageBox.Show("Missing file is : " + exception.FileName);
    }
    Assert.AreEqual(expected, actual);
}

getstate函数是

namespace GUI
{
    public class test
    {
        public bool getstate()
        {
            bool chk = false;
            bool result;
            String a = "some path";
            String b = "some path";
            String c = "some path";
            managed  objct;
            objct = new  managed();
            objct.Initialize(a, b, c, chk);
            objct.Execute(); //calls the C++/CLI execute which calls unmanaged C++
            result = objct.Executionresult(); //gets a bool result
            return result;
        }
    }
}

很抱歉,如果我让它感到困惑。请询问您是否需要更多信息。提前致谢

0 个答案:

没有答案