Skip to content

Running Your First Test

Test Case

In the following test cases: - A Todo object testTodo is created. (Our Todo class has the following methods ID, Product, Name, Email and Message) - The behaviors of each method is tested.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using DotNetCoreSqlDb.Models;
using System;

namespace ModelApp.Tests
{
    [TestClass]
    public class TodoTests
    {
        Todo testTodo = new Todo();

        [TestMethod]
        public void Test_TodoId()
        {
            testTodo.ID = 1;
            var testResult = testTodo.ID;
            Assert.AreEqual(1,testResult);
        }

        [TestMethod]
        public void Test_TodoProduct()
        {
            testTodo.Product = "Auto";
            var testResult = testTodo.Product;
            Assert.AreEqual("Auto", testResult);
        }

        [TestMethod]
        public void Test_TodoName()
        {
            testTodo.Name = "test name";
            var testResult = testTodo.Name;
            Assert.AreEqual("test name", testResult);
        }
    }
}

Running Tests

To execute the above test cases, run the following command from the terminal:

dotnet test ModelApp.Tests/