Мой модульный тест выглядит следующим образом. < /p>
Код: Выделить всё
public class EbaySharpTests
{
private EbayController ebayController;
private string accessToken = "";
private IConfiguration Configuration { get; }
public EbaySharpTests()
{
var builder = new ConfigurationBuilder().AddUserSecrets().AddEnvironmentVariables();
Configuration = builder.Build();
}
[SetUp]
public async Task Setup()
{
AuthenticationController authenticationController = new();
ClientCredentials clientCredentials = await authenticationController.GetClientCredentials(Configuration["clientId"]
, Configuration["clientSecret"]
, Configuration["refreshToken"]
, "https://api.ebay.com/oauth/api_scope");
accessToken = clientCredentials.AccessToken;
ebayController = new EbayController(accessToken);
}
[Test]
public void Test_AccessTokenNotEmpty()
{
Assert.That(string.IsNullOrEmpty(accessToken) == false);
}
}
Все это хорошо работает локально, а также отлично работает в действиях GitHub. Здесь "src =" https://i.sstatic.net/2d64x5m6.png "/>
My Github Workflow File имеет:
Код: Выделить всё
name: Build and Test
on:
workflow_dispatch:
push:
branches: [main]
jobs:
Build_and_Test:
env:
SLN_FILE: "/home/runner/work/EbaySharp/EbaySharp/EbaySharp.sln"
REPORTS_PATH: "./test-reports/build_$GITHUB_RUN_ATTEMPT"
clientId: ${{ secrets.CLIENT_ID }}
clientSecret: ${{ secrets.CLIENT_SECRET }}
refreshToken: ${{ secrets.REFRESH_TOKEN }}
runs-on: ubuntu-latest
permissions:
checks: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 #fetch-depth is needed for GitVersion
- name: Setup .NET
#Build/pack the project
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Verify solution Path
run: ls -la $SLN_FILE
- name: Restore dependencies
run: dotnet restore $SLN_FILE
- name: Build
run: dotnet build --no-restore --configuration Release $SLN_FILE
# - name: Display secrets
# run: |
# echo clientId: $clientId
# echo clientSecret: $clientSecret
- name: Test
run: dotnet test --verbosity normal --logger "trx;LogFileName=test-results.trx" --results-directory "TestResults" --configuration Release $SLN_FILE
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if previous step failed
with:
name: EbaySharp Tests # Name of the check run which will be created
reporter: dotnet-trx # Format of test results
list-tests: "all"
fail-on-error: "true"
#artifact: test-results
path: ${{ github.workspace }}/TestResults/test-results.trx # Path to test results (inside artifact .zip)
# TestReport:
# steps:
# - name: Test
# run: dotnet test --verbosity normal --logger "trx;LogFileName=test-results.trx" --results-directory "TestResults" --configuration Release $SLN_FILE
и ariale As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As As AS AS AS AS AS AS AS AS AS VARIAIL. Здесь < /p>
Код: Выделить всё
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
enableDefaultLogger: false
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\bin\**\*test.dll
**\bin\**\*tests.dll
searchFolder: '$(System.DefaultWorkingDirectory)'
testRunTitle: 'Test Results'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
env:
clientId: $(CLIENT_ID)
clientSecret: $(CLIENT_SECRET)
.>
Подробнее здесь: https://stackoverflow.com/questions/796 ... but-not-in