lundi 29 février 2016

How can I get MSTest to create tests for all the methods in a project?

When I created a new project in my solution, it created a class in my Test project like this:

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

namespace AYttFMScheduler.Tests
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
        }
    }
}

Then I thought I should be able to generate test methods corresponding to all the methods in my main project, but when I right-clicked a method in my main project and selected "Create Unit Tests" it generated this separate file in my Test project (after I selected the existing test project in the dialog) with only one test method, for the method I right-clicked, generated:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using AYttFMScheduler;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AYttFMScheduler.Tests
{
    [TestClass()]
    public class AYttFMConstsAndUtilsTests
    {
        [TestMethod()]
        public void SerializeStudentsFileTest()
        {
            Assert.Fail();
        }
    }
}

First, I wonder why the vast difference between the two? The creation of the method corresponding to the one I right-clicked (SerializeStudentsFileTest) makes sense, as does the default code within that test method (Assert.Fail()), but why the superfluous parens appended to "TestClass" and "TestMethod"?

Besides that oddity, and of primary concern to me, is that I think there should be an option when selecting "Create Unit Tests" to create them for the entire class, and even for the entire project. Surely there is a way, although I could not suss it out or google it to the fore.

Aucun commentaire:

Enregistrer un commentaire