Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

c# - Stepping through and debugging code in Unit tests

I have not been able to debug or step through unit test.

Here is my sample test code...

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DomainModel.Entities;
using DomainModel.Abstract;
using WebUI.Controllers;

namespace Tests
{
    [TestClass]
    public class PeopleControllerTests
    {

        static IPeopleRepository MockPeopleRepository(params Person[] people)
        {
            var mockPeopleRepos = new Moq.Mock<IPeopleRepository>();
            mockPeopleRepos.Setup(x => x.People).Returns(people.AsQueryable());
            return mockPeopleRepos.Object;
        }

        [TestMethod]

        public void Count_Of_People()
        {
            IPeopleRepository repository = MockPeopleRepository(
                new Person { Age = 31, Gender = "Male", Name = "Tom" },
                new Person { Age = 25, Gender = "Female", Name = "Sally" },
                new Person { Age = 18, Gender = "Female", Name = "John" }
                );

            PeopleController controller = new PeopleController(repository);
            var people = controller.List().ViewData.Model;
            var peoplelist = people as IList<Person>;
            Assert.AreEqual(3, peoplelist.Count);
        }

    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When using Microsoft.VisualStudio.TestTools.UnitTesting, go to 'Test' in the main menu of VS 2010, click submenu 'Debug' -> 'tests in current context'.

Right-clicking on the test-code and selecting 'run tests' will never start the debugger, not even when mode = debug.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...