Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Friday, 16 January 2009
( Testing )



Girl and man looking towards Mt Cook, NZ.

To get nUnit working on VS 2008 Express, firstly download and install nUnit.

Make a new console application.  Add the 3 nunit references you see below



Open up the .csproj file.. in my case in: C:\code\stuff\HowNUnitInspiredConsole\HowNUnitInspiredConsole\HowNUnitInspiredConsole.csproj

Where you see... add in the two Startxxx lines.

 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files\NUnit 2.4.8\bin\nunit.exe</StartProgram>
   
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>

Here is my first unit test for a web app:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Web.Script.Serialization;
using System.Web.Util;
using System.Net;
using System.Web;
using System.IO;
using System.Diagnostics;

namespace HowNUnitInspiredConsole
{
    class NUnitConsoleRunner
    {
        [STAThread]
        static void Main(string[] args)
        {
            NUnit.ConsoleRunner.Runner.Main(args);
        }
    }

    [TestFixture]
    public class FormTest
    {
        // 1 is dev / local
        // 2 is test
        int debugbit = 2;

        string targetUri = "";
        string targetUriNoHTTP = "";

        [SetUp]
        public void Init()
        {
            if (debugbit == 1)
            {
                targetUri = "http://192.168.139.128/drink/";
                targetUriNoHTTP = "192.168.139.128/drink/";
            }

            if (debugbit == 2)
            {
                targetUri = "http://www.davemateer.com/drink/";
                targetUriNoHTTP = "www.davemateer.com/drink/";
            }
        }

        [Test]
        public void helloWorld()
        {
            WebClient client = new WebClient();
            StreamReader reader = new StreamReader(client.OpenRead(targetUri + "test/helloWorld.php"));
            string responseFromServer = reader.ReadToEnd();

            Assert.AreEqual("Hello World", responseFromServer);
        }
    }
}



When the nUnit gui popped up, make sure it gets the correct .exe file.  I had to do a project add assembly, while the application was running.

Run your application which should pop up with something like this: