Skip to content

Commit

Permalink
[docs] add test environment documentation (#20)
Browse files Browse the repository at this point in the history
Resolves #18
  • Loading branch information
shawnfunke authored May 9, 2023
1 parent 085b6a5 commit 5ee179c
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,116 @@ npm run build:dev

> Create a development build of the extension.
## Testing

A C# unit-test project can be used to test the extension in a self-owned Azure
DevOps organisation.

```csharp
[TestClass]
public class UnitTests
{
public TestContext? TestContext { get; set; }

[TestCleanup]
public void TestCleanup()
{
this.TestContext!.AddResultFile("./attachments/test.svg");
this.TestContext!.AddResultFile("./attachments/test.mp4");
this.TestContext!.AddResultFile("./attachments/test.html");
this.TestContext!.AddResultFile("./attachments/test.pdf");
this.TestContext!.AddResultFile("./attachments/test.yaml");
this.TestContext!.AddResultFile("./attachments/test.txt");
this.TestContext!.AddResultFile("./attachments/fake.pdf");
}

[TestMethod]
public void TestMethod_Pass()
{
Assert.AreEqual("abc", "abc");
}

[TestMethod]
public void TestMethod_Fail()
{
Assert.AreEqual("abc", "123");
}
}
```

> Example unit-test class that uploads the release pipeline attachments.
```yaml
steps:

- task: VisualStudioTestPlatformInstaller@1
displayName: 'Install Visual Studio Test Platform'
inputs:
versionSelector: latestStable

- task: NuGetToolInstaller@1
displayName: 'Use NuGet'
inputs:
checkLatest: true

- powershell: |
New-Item -ItemType Directory -Force -Path $(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project\attachments
Invoke-WebRequest "https://filesamples.com/samples/image/svg/sample_640%C3%97426.svg" -OutFile $(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project\attachments\test.svg
Invoke-WebRequest "https://filesamples.com/samples/video/mp4/sample_960x540.mp4" -OutFile $(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project\attachments\test.mp4
Invoke-WebRequest "https://filesamples.com/samples/code/html/sample1.html" -OutFile $(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project\attachments\test.html
Invoke-WebRequest "https://filesamples.com/samples/document/pdf/sample3.pdf" -OutFile $(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project\attachments\test.pdf
Invoke-WebRequest "https://filesamples.com/samples/code/yaml/invoice.yaml" -OutFile $(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project\attachments\test.yaml
Invoke-WebRequest "https://filesamples.com/samples/code/yaml/invoice.yaml" -OutFile $(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project\attachments\test.txt
Invoke-WebRequest "https://filesamples.com/samples/code/html/sample1.html" -OutFile $(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project\attachments\fake.pdf
displayName: Setup

- task: NuGetCommand@2
displayName: 'NuGet Restore'
inputs:
restoreSolution: '$(System.DefaultWorkingDirectory)/_ado-attachment-previewer-tests/test-project/test-project.sln'

- task: MSBuild@1
displayName: 'Build Solution'
inputs:
solution: '$(System.DefaultWorkingDirectory)/_ado-attachment-previewer-tests/test-project/test-project.sln'
msbuildArchitecture: x64

- powershell: |
Move-Item $(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project\attachments $(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project\bin\Debug\net6.0\attachments
displayName: 'Move Attachments'

- task: VSTest@2
displayName: 'Run Visual Studio Tests Without Reruns'
inputs:
testAssemblyVer2: '**\test-project.dll'
searchFolder: '$(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project'
vsTestVersion: toolsInstaller
continueOnError: true

- task: VSTest@2
displayName: 'Run Visual Studio Tests With Reruns'
inputs:
testAssemblyVer2: '**\test-project.dll'
searchFolder: '$(System.DefaultWorkingDirectory)\_ado-attachment-previewer-tests\test-project'
vsTestVersion: toolsInstaller
rerunFailedTests: true
rerunType: basedOnTestFailureCount
continueOnError: true

- task: PublishTestResults@2
displayName: Publish
inputs:
testResultsFormat: NUnit
testResultsFiles: testresult.xml
searchFolder: '$(Agent.TempDirectory)/TestResults'
continueOnError: true
```
> Exported YAML of steps for release pipeline. Requires the git repository that
> includes the C# unit-test project as an artifact.
## Maintainers
- [@shawnfunke](https://github.com/shawnfunke)

0 comments on commit 5ee179c

Please sign in to comment.