test: 更新分析功能和迁移测试用例

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Scottxjw
2026-08-25 11:30:16 +08:00
parent ee8ea29265
commit 7a8a1e9a87
9 changed files with 602 additions and 122 deletions

View File

@@ -1,6 +1,7 @@
using Gpulse.WCT.DataAnalyzer.Commands;
using Gpulse.WCT.DataAnalyzer.Core.Application;
using Gpulse.WCT.DataAnalyzer.Core.Application.Analysis;
using Gpulse.WCT.DataAnalyzer.Core.Application.Exporting;
using Microsoft.Extensions.DependencyInjection;
namespace Gpulse.WCT.DataAnalyzer.Tests;
@@ -13,10 +14,31 @@ public abstract class CommandTestBase
protected CliTestHost Host { get; private set; } = null!;
[SetUp]
public async Task SetUp() => Host = await CliTestHost.CreateAsync();
public async Task SetUp()
{
// 清理 Datas 和 Output 文件夹,避免测试间干扰
CleanupDatasAndOutput();
Host = await CliTestHost.CreateAsync();
}
[TearDown]
public void TearDown() => Host.Dispose();
public void TearDown()
{
Host.Dispose();
// 测试结束后再次清理
CleanupDatasAndOutput();
}
/// <summary>
/// 清理 Datas 和 Output 文件夹
/// </summary>
protected static void CleanupDatasAndOutput()
{
var datasDir = Path.Combine(AppContext.BaseDirectory, "Datas");
var outputDir = Path.Combine(AppContext.BaseDirectory, "Output");
if (Directory.Exists(datasDir)) Directory.Delete(datasDir, true);
if (Directory.Exists(outputDir)) Directory.Delete(outputDir, true);
}
// 命令构造方式与 Program.Main 一致:从 DI 解析服务再构造命令
protected ParseCommand Parse() => new(Host.Services.GetRequiredService<ParseService>());
@@ -29,7 +51,8 @@ public abstract class CommandTestBase
protected AnalyzeCommand Analyze() => new(
Host.Services.GetRequiredService<PlossAnalysisService>(),
Host.Services.GetRequiredService<QfodCalibrationService>());
Host.Services.GetRequiredService<QfodCalibrationService>(),
Host.Services.GetRequiredService<AnalyzeExcelExporter>());
/// <summary>在测试临时目录下新建一个子目录。</summary>
protected string NewDir() =>