From a2aba4c9b0977f1fabdda29a5a9516d8e9700bd4 Mon Sep 17 00:00:00 2001 From: zhuzhiwei Date: Thu, 19 Nov 2026 10:31:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 11 +++++++++++ .gitignore | 7 +++++++ Dockerfile | 22 ++++++++++++++++++++++ Tests/UnitTest1.cs | 10 ++++++++++ TySpace.Ttc.RegressionSuite.csproj | 26 ++++++++++++++++++++++++++ docker-compose.yml | 9 +++++++++ 6 files changed, 85 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Tests/UnitTest1.cs create mode 100644 TySpace.Ttc.RegressionSuite.csproj create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b5793ac --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +**/bin/ +**/obj/ +**/TestResults/ +**/.vs/ +**/.vscode/ +.git/ +.gitignore +Dockerfile* +docker-compose* +*.user +*.suo diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..561693f --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +bin/ +obj/ +TestResults/ +.vs/ +.vscode/ +*.user +*.suo diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a908057 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# 测试项目用 SDK 镜像即可(dotnet test 需要 SDK,而不是 runtime) +# 注意:这里不写 `# syntax=docker/dockerfile:1`,避免额外拉取 dockerfile 前端镜像 +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS test +WORKDIR /src + +ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 \ + DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 \ + DOTNET_NOLOGO=1 + +# 1) 先只复制 csproj 做 restore,充分利用 Docker 层缓存 +COPY TySpace.Ttc.RegressionSuite.csproj ./ +RUN dotnet restore TySpace.Ttc.RegressionSuite.csproj + +# 2) 再复制源码并预编译,让编译错误在 build 阶段就暴露 +COPY . . +RUN dotnet build TySpace.Ttc.RegressionSuite.csproj -c Release --no-restore + +# 3) 容器启动即跑测试;结果写到 /src/TestResults,可挂载出来 +ENTRYPOINT ["dotnet", "test", "TySpace.Ttc.RegressionSuite.csproj", \ + "-c", "Release", "--no-build", "--no-restore", \ + "--logger", "trx;LogFileName=test-results.trx", \ + "--results-directory", "/src/TestResults"] diff --git a/Tests/UnitTest1.cs b/Tests/UnitTest1.cs new file mode 100644 index 0000000..6bee782 --- /dev/null +++ b/Tests/UnitTest1.cs @@ -0,0 +1,10 @@ +namespace TySpace.Ttc.RegressionSuite; + +public class UnitTest1 +{ + [Fact] + public void Test1() + { + + } +} \ No newline at end of file diff --git a/TySpace.Ttc.RegressionSuite.csproj b/TySpace.Ttc.RegressionSuite.csproj new file mode 100644 index 0000000..5336066 --- /dev/null +++ b/TySpace.Ttc.RegressionSuite.csproj @@ -0,0 +1,26 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ef938ba --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + regression-suite: + build: + context: . + dockerfile: Dockerfile + image: tyspace-ttc-regressionsuite-tests:latest + # 把测试报告(trx)输出到宿主机,方便 CI 或本地查看 + volumes: + - ./TestResults:/src/TestResults