You're essentially looking for unit testing. In C#, I am partial to nunit, though there are other testing suites, and they all do roughly the same thing.
Here's a breakdown of an nunit test:
[TestFixture] // 2
public class CalculatorTests // 1
{
[Test] // 4
public void Sum_of_two_numbers() // 3
{
// Arrange
double first = 10;
double second = 20;
var calculator = new Calculator();
// Act
double result = calculator.Sum(first, second);
// Assert
Assert.Equal(30, result);
}
}
Comments:
- A class serves as a container for a series of tests.
- The
TextFixture
attribute lets Nunit know about (1). Test frameworks do automated discovery of tests.
- The name of the unit test.
- The
[Test]
attribute tells Nunit that we are declaring a test.
- The ARRANGE section of a test creates the conditions for the test. This setup is trivial, but the arrange section can be quite complex!
- The ACT section of a test actually runs the test or tests.
- The ASSERT section makes sure that the appropriate result(s) took place.
If you want a web tool that simplifies your workflow tremendously, you can use something like GitHub Classroom or CodingRooms, which will both accept submissions and apply the tests automatically (and give you a nice readout as well!), though be aware that these are both paid platforms. (I was especially impressed by CodingRooms at a workshop I attended.)