https://github.com/lostbeard/spawndev.blazor.unittesting
Unit testing for Blazor
https://github.com/lostbeard/spawndev.blazor.unittesting
Last synced: 3 months ago
JSON representation
Unit testing for Blazor
- Host: GitHub
- URL: https://github.com/lostbeard/spawndev.blazor.unittesting
- Owner: LostBeard
- License: mit
- Created: 2024-07-22T19:35:08.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-22T19:35:27.000Z (about 1 year ago)
- Last Synced: 2025-07-19T05:39:51.634Z (3 months ago)
- Language: C#
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
## NuGet
| Package | Description | Link |
|---------|-------------|------|
|**SpawnDev.Blazor.UnitTesting**| Blazor Unit Testing | [](https://www.nuget.org/packages/SpawnDev.Blazor.UnitTesting) |
# SpawnDev.Blazor.UnitTesting
[](https://www.nuget.org/packages/SpawnDev.Blazor.UnitTesting)Unit testing for Blazor
Supports .Net Blazor 6, 7, and 8.
Create a page for your test. Add the UnitTestsView component and assign the TestAssemblies and/or TestTypes parameters.
Give your unit test class the TestClass attribute and tag your public instance test methods with the TestMethod attribute. Example unit test class below.
```cs
[TestClass]
public class UnitTestExamples {[TestMethod]
public void NotImplementedTest() {
throw new NotImplementedException();
}[TestMethod]
public void ThreadSleepTest() {
Thread.Sleep(1000);
}[TestMethod]
public async Task TaskDelayTest() {
await Task.Delay(1000);
}[TestMethod]
public string ReturnAdditionalFailureInfo()
{
throw new Exception("Additional error info");
}[TestMethod]
public string ReturnValueTest()
{
return "Additional success info";
}[TestMethod]
public async Task ReturnValueTestAsync()
{
await Task.Delay(1);
return "Additional success info";
}
}
```Example page for displaying your unit tests.
```cs
@using SpawnDev.Blazor.UnitTesting
@using System.Reflection@page "/UnitTests"
@code {
IEnumerable? _assemblies = new List {
typeof(UnitTestsView).Assembly,
typeof(UnitTests).Assembly
};
}
```