The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Using NUnit and a better way to Unit Test with External File Dependancies

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Scott Hanselman

Posts: 1031
Nickname: glucopilot
Registered: Aug, 2003

Scott Hanselman is the Chief Architect at Corillian Corporation and the Microsoft RD for Oregon.
Using NUnit and a better way to Unit Test with External File Dependancies Posted: Jun 22, 2004 7:16 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Scott Hanselman.
Original Post: Using NUnit and a better way to Unit Test with External File Dependancies
Feed Title: Scott Hanselman's ComputerZen.com
Feed URL: http://radio-weblogs.com/0106747/rss.xml
Feed Description: Scott Hanselman's ComputerZen.com is a .NET/WebServices/XML Weblog. I offer details of obscurities (internals of ASP.NET, WebServices, XML, etc) and best practices from real world scenarios.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Scott Hanselman
Latest Posts From Scott Hanselman's ComputerZen.com

Advertisement

Great stuff on using NUnit in conjunction with external files from Patrick Cauldwell.  It's one of those "Doh!" things that I've always MEANT to do, but somehow ended up using Pre- and Post-Build events instead.  I MUCH prefer Patrick's method.  It's much cleaner and it allows the once-external file to LIVE with the test.

        [SetUp] public void SetUp()
        {
            Assembly a = Assembly.GetExecutingAssembly();
            using (Stream s = a.GetManifestResourceStream("MyNameSpace.something.txt"))
            {
                using (StreamReader sr = new StreamReader(s))
                {
                    using (StreamWriter sw = File.CreateText(webConfigPath))
                    {
                        sw.Write(sr.ReadToEnd());
                        sw.Flush();
                    }
                }
            }
        }

        [TearDown] public void TearDown()
        {
            if(File.Exists(webConfigPath))
            {
                File.Delete(webConfigPath);
            }
        }

Read: Using NUnit and a better way to Unit Test with External File Dependancies

Topic: Get a record count for all tables in a database Previous Topic   Next Topic Topic: Spiderman in Dhothi

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use