Azure Pipeline - 在测试应用程序中启动服务器

问题描述

我有一个 XUnit 项目,它在启动时会在类构造函数中初始化一个服务器:

public OPcuaSampleServerTest(OPCTagList oPCTagList)
{
    MySampleServer server = new(true,3600,null);
    this.thread = new Thread(() => server.Run());
    this.thread.Start();
    this._taglist = oPCTagList.Taglist;
}

使用服务器的测试通过 localhost 与它通信,并且在我的机器上一切正常。我还通过克隆代码对其进行了测试,以确保存储库中存在所有内容。一切都按预期编译。我正在尝试在 Azure 管道上获得相同的结果。我有一个工作管道,可以在没有服务器的情况下构建和运行初始测试用例。现在添加这个 OPcuaSampleServerTest 后,测试在服务器上失败,但在我的机器上没有。错误是无法连接到服务器

OPcuaClass opc = new("localhost","51210",this._taglist,300,false);
bool connected = opc.InitializeOPcuaClient(); //returns false on server,and true on running it on my own machine

因此,我认为问题在于它无法看到/连接到 localhost。管道中的测试函数中是否缺少某些特定设置,如下所示:

- task: DotNetCoreCLI@2
  displayName: Test xUnit
  inputs:
    command: test
    projects: '**/OPCDLL.Test.csproj'
    arguments: '--configuration $(buildConfiguration) --collect "Code coverage" --no-build'
    testRunTitle: 'Generic Repository Tests'
    publishTestResults: true

使用 dotnet CLI 运行我认为相同的函数

dotnet test OPCDLL.Test.csproj  --configuration Release --collect "Code coverage" --no-build --framework net5.0

我通过了 4 次测试,这是应该的。那么蔚蓝的运行中肯定有什么虚假的东西?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...