You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过C#调用SOAPUI测试用例多次运行并保存响应至单个文件?

解决SOAPUI测试用例多次调用响应追加到同一文件的问题

方法1:通过SOAPUI脚本实现响应追加

打开TERMEKADAT测试用例对应的请求,切换到「Script」标签,用Groovy脚本实现文件追加逻辑:

// 替换为你的目标文件路径
def targetFile = new File("C:/your/output/responses.txt")
// 获取当前请求的响应内容
def responseContent = context.response.contentAsString
// 追加内容到文件,添加换行分隔不同响应
targetFile.append(responseContent + "\n\n")

每次执行请求时,脚本会自动把响应内容追加到指定文件,不会覆盖原有数据。

方法2:C#代码捕获命令行输出并追加

如果坚持用命令行调用SOAPUI,不要直接用SOAPUI自带的dump文件参数(默认覆盖模式),改为在C#里捕获输出后自行追加:

string soapUIRunnerPath = @"C:\Program Files\SmartBear\SoapUI-5.7.0\bin\testrunner.bat";
string testCaseParams = "-s\"TERMEKADAT\" \"C:/your/project/your-soapui-project.xml\"";

var startInfo = new ProcessStartInfo(soapUIRunnerPath, testCaseParams)
{
    RedirectStandardOutput = true,
    UseShellExecute = false,
    CreateNoWindow = true
};

using (var process = Process.Start(startInfo))
{
    string response = process.StandardOutput.ReadToEnd();
    process.WaitForExit();
    // 追加响应到目标文件,添加分隔符
    File.AppendAllText(@"C:/your/output/responses.txt", response + Environment.NewLine + Environment.NewLine);
}

这种方式由C#代码完全控制文件写入逻辑,避免SOAPUI默认的覆盖行为。

方法3:使用SOAPUI的DataSink测试步骤

如果是在SOAPUI内编排测试流程,可添加DataSink步骤实现追加:

  • 在TERMEKADAT测试用例末尾添加「DataSink」步骤
  • 配置DataSink类型为「File」,选择目标文件,将「Write Mode」设置为「Append」
  • 映射请求的响应内容到DataSink的输出字段,每次执行测试用例时,响应会自动追加到文件

内容的提问来源于stack exchange,提问作者maruzsam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 06:05:21