0 day streak
csharp / beginner
Snippet

Simple Test Assertion Principle

A manual test assertion checks if the actual result matches the expected value, throwing an error if it doesn't.

snippet.cs
csharp
1
2
3
4
5
int result = 5 + 5;
if (result != 10) {
throw new Exception("Calculation failed");
}
Console.WriteLine("Test Passed");
Breakdown
1
if (result != 10) {
Checks if the actual result is different from the expected value 10.
2
throw new Exception(...);
Signals a failure by interrupting the program flow.