Click here to Skip to main content
13,249,504 members (37,338 online)
Click here to Skip to main content

Stats

27.3K views
398 downloads
21 bookmarked
Posted 30 Sep 2009

How to quickly debug a NUnit test in Visual Studio

, 30 Sep 2009
An article on quickly debugging NUnit tests.
Jonno.Extensions.dll
Jonno.AddIns.NunitHelper.dll
Jonno.AddIns.Logic.VisualStudioSpecific.dll
Jonno.AddIns.Entities.dll
Jonno.SimpleTestRunner.exe
Jonno Nunit Helper.AddIn
Jonno.Utilities.dll
Jonno.SimpleTestRunner.Logic.dll
Jonno.SimpleTestRunner.Entities.dll
Jonno.Extensions.UnitTests
Properties
vssver2.scc
Jonno.Logic.SimpleTestRunner
Properties
vssver2.scc
vssver2.scc
Jonno.SimpleTestRunner
Properties
vssver2.scc
vssver2.scc
Jonno.SimpleTestRunner.Entities
Properties
vssver2.scc
vssver2.scc
Jonno.Utilities
Properties
vssver2.scc
vssver2.scc
Jonno Nunit Helper.AddIn
Jonno.AddIns.Entities
Properties
vssver2.scc
vssver2.scc
Jonno.AddIns.Entities.UnitTests
Properties
vssver2.scc
vssver2.scc
Jonno.AddIns.Logic.EnvDTE
Properties
vssver2.scc
vssver2.scc
Jonno.AddIns.NunitHelper
bin
Properties
vssver2.scc
vssver2.scc
Jonno.Extensions
Properties
vssver2.scc
//-------------------------------------------------------------------------------------
// <copyright file='CodeFileTests.cs' company='Jonno'>
//     Copyright (c) Paul Johnson 2009 (email:paulmichael.johnson@gmail.com)
//     Code is released under The Code Project Open License (CPOL).
// </copyright>
//-------------------------------------------------------------------------------------

namespace Jonno.AddIns.Entities.UnitTests
{
    using Jonno.AddIns.Entities;
    using NUnit.Framework;

    [TestFixture]
    public class CodeFileTests
    {        
        /// <summary>
        /// The system under test;
        /// </summary>
        private CodeFile sut;

        [Test]
        public void IfFileIsAssemblyInfoShouldSetFlag()
        {
            this.sut = new MockCodeFile(@"c:\swsws\sws\AssemblyInfo.cs");
            Assert.That(this.sut.IsAssemblyInfo, Is.EqualTo(true), "true");

            this.sut = new MockCodeFile(@"c:\swsws\sws\Someclass.cs");
            Assert.That(this.sut.IsAssemblyInfo, Is.EqualTo(false), "false");
        }

        [Test]
        public void IfFileIsCSharpShouldSetFlag()
        {
            this.sut = new MockCodeFile(@"c:\swsws\sws\AssemblyInfo.cs");
            Assert.That(this.sut.IsCSharpFile, Is.EqualTo(true), "true");

            this.sut = new MockCodeFile(@"c:\swsws\sws\Someclass.vb");
            Assert.That(this.sut.IsCSharpFile, Is.EqualTo(false), "false");
        }

        [Test]
        public void IfFileIsVBShouldSetFlag()
        {
            this.sut = new MockCodeFile(@"c:\swsws\sws\AssemblyInfo.vb");
            Assert.That(this.sut.IsVBFile, Is.EqualTo(true), "true");

            this.sut = new MockCodeFile(@"c:\swsws\sws\Someclass.cs");
            Assert.That(this.sut.IsVBFile, Is.EqualTo(false), "false");
        }

        [Test]
        public void ShouldSetExtension()
        {
            this.sut = new MockCodeFile(@"c:\swsws\sws\AssemblyInfo.vb");
            Assert.That(this.sut.Extension, Is.EqualTo(".vb"));

            this.sut = new MockCodeFile(@"c:\swsws\sws\AssemblyInfo.cs");
            Assert.That(this.sut.Extension, Is.EqualTo(".cs"));

            this.sut = new MockCodeFile(@"c:\swsws\sws\SomeXML.xml");
            Assert.That(this.sut.Extension, Is.EqualTo(".xml"));
        }

        [Test]
        public void ShouldSetFilenameWithoutExtension()
        {
            this.sut = new MockCodeFile(@"c:\swsws\sws\AssemblyInfo.vb");
            Assert.That(this.sut.FileNameWithoutExtension, Is.EqualTo("AssemblyInfo"));

            this.sut = new MockCodeFile(@"c:\swsws\sws\SomeClass.cs");
            Assert.That(this.sut.FileNameWithoutExtension, Is.EqualTo("SomeClass"));

            this.sut = new MockCodeFile(@"c:\swsws\sws\SomeXML.xml");
            Assert.That(this.sut.FileNameWithoutExtension, Is.EqualTo("SomeXML"));
        }

        [Test]
        public void ShouldSetShortname()
        {
            this.sut = new MockCodeFile(@"c:\swsws\sws\AssemblyInfo.vb");
            Assert.That(this.sut.ShortName, Is.EqualTo("AssemblyInfo.vb"));

            this.sut = new MockCodeFile(@"c:\swsws\sws\SomeClass.cs");
            Assert.That(this.sut.ShortName, Is.EqualTo("SomeClass.cs"));

            this.sut = new MockCodeFile(@"c:\swsws\sws\SomeXML.xml");
            Assert.That(this.sut.ShortName, Is.EqualTo("SomeXML.xml"));
        }
        
        [Test]
        public void IfVborCSharpFileShouldGetText()
        {
            var expected = "Public class Paul { public void jjj() {  } }";

            this.sut = new MockCodeFile(@"c:\swsws\sws\SomeClass.cs", expected);
            Assert.That(this.sut.Text, Is.EqualTo(expected));

            this.sut = new MockCodeFile(@"c:\swsws\sws\SomeClass.vb", expected);
            Assert.That(this.sut.Text, Is.EqualTo(expected));

            this.sut = new MockCodeFile(@"c:\swsws\sws\SomeXMl.xml", expected);
            Assert.That(this.sut.Text, Is.EqualTo(string.Empty));
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Paul "Jonno" Johnson
Software Developer (Senior)
United Kingdom United Kingdom
I have over 15 years of development experience, in many different languages, programming styles and platforms. Currently working as a C# coder, and residing in north Herts in the UK. I love lean software development and anything that reduces a grind to leave more time for useful coding!

You may also be interested in...

Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 30 Sep 2009
Article Copyright 2009 by Paul "Jonno" Johnson
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid