mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-04-07 11:26:41 +00:00
Move Unit Tests notes to dedicated file
This commit is contained in:
parent
be033e7902
commit
6e4e0c19e6
2 changed files with 41 additions and 38 deletions
|
@ -2860,44 +2860,6 @@ match.Groups[index].Index; // position in the input string of the matched group
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Unit Testing
|
|
||||||
|
|
||||||
[Microsoft Unit Testing Tutorial](https://docs.microsoft.com/en-us/visualstudio/test/walkthrough-creating-and-running-unit-tests-for-managed-code?view=vs-2019)
|
|
||||||
|
|
||||||
To test a project add a **MSTest Test Projet** to the solution.
|
|
||||||
|
|
||||||
The test runner will execute any methods marked with `[TestInitialize]` once for every test the class contains, and will do so before running the actual test method itself.
|
|
||||||
The `[TestMethod]` attribute tells the test runner which methods represent tests.
|
|
||||||
|
|
||||||
In `TestClass.cs`:
|
|
||||||
|
|
||||||
```cs
|
|
||||||
using System;
|
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
||||||
|
|
||||||
namespace Project.Tests
|
|
||||||
{
|
|
||||||
[TestClass]
|
|
||||||
public class TestClass
|
|
||||||
{
|
|
||||||
[TestMethod]
|
|
||||||
public void TestMethod()
|
|
||||||
{
|
|
||||||
Assert.AreEqual(expected, actual);
|
|
||||||
Assert.IsTrue(bool);
|
|
||||||
Assert.IsFalse(bool);
|
|
||||||
Assert.IsNotNull(nullable);
|
|
||||||
|
|
||||||
// assertions on collections
|
|
||||||
CollectionAssert.AreEqual(expexcted, actual),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
[UnitTest Overloaded Methods](https://stackoverflow.com/a/5666591/8319610)
|
|
||||||
[Naming standards for unit tests](https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html)
|
|
||||||
|
|
||||||
## Performance Tips
|
## Performance Tips
|
||||||
|
|
||||||
### Bit Tricks
|
### Bit Tricks
|
||||||
|
|
41
.NET/C#/Unit Testing.md
Normal file
41
.NET/C#/Unit Testing.md
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# Unit Testing
|
||||||
|
|
||||||
|
## MSTest
|
||||||
|
|
||||||
|
[Microsoft Unit Testing Tutorial](https://docs.microsoft.com/en-us/visualstudio/test/walkthrough-creating-and-running-unit-tests-for-managed-code?view=vs-2019)
|
||||||
|
|
||||||
|
To test a project add a **MSTest Test Projet** to the solution.
|
||||||
|
|
||||||
|
The test runner will execute any methods marked with `[TestInitialize]` once for every test the class contains, and will do so before running the actual test method itself.
|
||||||
|
The `[TestMethod]` attribute tells the test runner which methods represent tests.
|
||||||
|
|
||||||
|
In `TestClass.cs`:
|
||||||
|
|
||||||
|
```cs
|
||||||
|
using System;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
|
namespace Project.Tests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class TestClass
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void TestMethod()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(expected, actual);
|
||||||
|
Assert.IsTrue(bool);
|
||||||
|
Assert.IsFalse(bool);
|
||||||
|
Assert.IsNotNull(nullable);
|
||||||
|
|
||||||
|
// assertions on collections
|
||||||
|
CollectionAssert.AreEqual(expexcted, actual),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
[UnitTest Overloaded Methods](https://stackoverflow.com/a/5666591/8319610)
|
||||||
|
[Naming standards for unit tests](https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html)
|
Loading…
Add table
Reference in a new issue