posted on Thursday, December 02, 2004 9:36 AM by anoras

Unit testing with Cassini and NUnitASP – A complete example

Yesterday, I posted a short entry linking to Scott Hanselmans great article on how he used Cassini to unit test web forms without having Internet Information Server installed on the test server. I made a short comment on exchanging Scott’s simple smoke test with a NUnitASP test case to do more advanced testing. Judging from some of the feedback I got, I decided to give a complete example of how you can use Cassini in combination with NUnitASP to unit test ASP.NET web pages without IIS. I’ve used Scott’s original code with some minor changes. In addition, I’m using my updated version of NUnitASP to make it handle setup and teardown correctly.
Below is the complete source code for my test fixture. The resource handling code and similar has been eluded for clarity.

using System;
using System.Diagnostics;
using System.IO;
using Cassini;
using NUnit.Extensions.Asp.AspTester;
using NUnit.Framework;
namespace Noras.Articles.CassiniWithNUnitASP.Tests {

            [TestFixture]
            public class Example : NUnit.Extensions.Asp.WebFormTestCase {
                        private Server webServer;
                        private int webServerPort=8086;
                        private string webServerVDir="/";
                        private string tempPath=AppDomain.CurrentDomain.BaseDirectory;
                        private string tempBinPath=Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"bin");
                        private string webServerUrl;
                        private string aspxPath=@"C:\Documents and Settings\anders.noras\My Documents\My Projects\Research\CassiniHostedExample\";

                        [SetUp]
                        new public void BaseSetUp() {
                                    base.BaseSetUp();
                                    Directory.CreateDirectory(tempBinPath);
                                    foreach(string file in Directory.GetFiles(tempPath,"*.dll")) {
                                                string newFile =
                                                Path.Combine(tempBinPath,Path.GetFileName(file));
                                                if (File.Exists(newFile)){File.Delete(newFile);}
                                                File.Copy(file,newFile);
                                    }
                                    foreach(string file in Directory.GetFiles(aspxPath,"*.aspx")) {
                                                string newFile = 
                                                Path.Combine(tempPath,Path.GetFileName(file));
                                                if (File.Exists(newFile)){File.Delete(newFile);}
                                                File.Copy(file,newFile);
                                    }

                                    //Start the internal Web Server
                                    webServer=new Server(webServerPort,webServerVDir,tempPath);
                                    webServerUrl=String.Format("http://localhost:{0}{1}",
                                    webServerPort,webServerVDir);
                                    webServer.Start();
                                   
// Let everyone know
                                    Debug.WriteLine(
String.Format("Web Server started on port {0} with VDir {1} in physical directory {2}",webServerPort,webServerVDir,tempPath));
                        }

                        [TearDown]
                        new public void BaseTearDown() {
                                    base.BaseTearDown();
                                    try {
                                                if (webServer!=null) {
                                                            webServer.Stop();
                                                            webServer=null;
                                                }
                                                Directory.Delete(tempBinPath,true);
                                    } catch {}

                        }

                        [Test]
                        public void SimpleTest() {
                                    Browser.GetPage(webServerUrl+"Default.aspx");
                                    Debug.WriteLine(Browser.CurrentPageText);
                                    LabelTester label1=new LabelTester("Label1",CurrentWebForm);
                                    AssertVisibility(label1,true);
                        }
            }
}

I’ve added a path to the aspx files to be tested to the class (aspxPath) and added code to copy the aspx files from this location to the physical Cassini web directory. Apart from that I have the SimpleTest test case which is similar to the case in my previous post.
Other files such as the Default.aspx page is similar to the one in Scott’s example.

As this example shows you can combine Scott’s clever Cassini test fixture with the power of NUnitASP. The solution should be perfect for unit testing within continuous integration environments and similar.

Comments

# re: Unit testing with Cassini and NUnitASP – A complete example @ Tuesday, May 29, 2007 10:26 AM

hentai ino naruto http://griffin.toonsbest.com/hentai-ino-naruto.html
protesting spontaneously SpongeBob http://suck.crazytoonsfree.com/SpongeBob-naked.html
Sleeping Beauty nude http://hairy.toonscentral.com/SleepingBeautynude.html
expression an incredibles porn http://sexy.crazytoonsfree.com/the-incredibles-comic-porn.html
futurama porn toons http://sexy.crazytoonsfree.com/futurama-porn-toons.html
believe free complained hentai http://Bratz.freetoonsexclusive.com/free-kim-possible-hentai.html
Naruto horny http://batman.freetoonsexclusive.com/Naruto-horny.html

obwihtq

# re: Unit testing with Cassini and NUnitASP – A complete example @ Tuesday, June 05, 2007 5:05 AM

Interesting...

Thanasios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Tuesday, June 05, 2007 3:12 PM

Cool...

Ioannis

# re: Unit testing with Cassini and NUnitASP – A complete example @ Tuesday, June 05, 2007 9:09 PM

interesting

Epaminondas

# re: Unit testing with Cassini and NUnitASP – A complete example @ Wednesday, June 06, 2007 11:14 AM

Interesting...

Grigorios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Wednesday, June 06, 2007 12:51 PM

Cool!

Aiolos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Thursday, June 07, 2007 7:53 PM

Interesting...

Leo

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 08, 2007 7:26 AM

Cool!

Maximos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 08, 2007 8:16 AM

Nice

Leandros

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 08, 2007 7:14 PM

Nice...

Aristides

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 08, 2007 8:05 PM

Sorry :(

Odysseas

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 09, 2007 1:03 AM

Cool!

Arsenios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 09, 2007 9:33 AM

Nice!

Anastasios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 09, 2007 10:30 AM

Interesting...

Savas

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 09, 2007 3:03 PM

Nice!

Aineias

# re: Unit testing with Cassini and NUnitASP – A complete example @ Sunday, June 10, 2007 1:49 PM

Cool...

Leandros

# re: Unit testing with Cassini and NUnitASP – A complete example @ Sunday, June 10, 2007 2:58 PM

Cool.

Kalinikos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Sunday, June 10, 2007 4:42 PM

Interesting...

Demosthenes

# re: Unit testing with Cassini and NUnitASP – A complete example @ Monday, June 11, 2007 11:48 AM

interesting

Fotis

# re: Unit testing with Cassini and NUnitASP – A complete example @ Tuesday, June 12, 2007 3:01 AM

Sorry :(

Romanos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Tuesday, June 12, 2007 7:03 PM

Nice...

Costa

# re: Unit testing with Cassini and NUnitASP – A complete example @ Wednesday, June 13, 2007 6:15 AM

interesting

Marios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Wednesday, June 13, 2007 6:33 AM

Cool!

Marios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Wednesday, June 13, 2007 5:09 PM

Nice...

Georges

# re: Unit testing with Cassini and NUnitASP – A complete example @ Wednesday, June 13, 2007 10:30 PM

Interesting...

Valerios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Wednesday, June 13, 2007 10:53 PM

Interesting...

Yannis

# re: Unit testing with Cassini and NUnitASP – A complete example @ Thursday, June 14, 2007 2:01 AM

Nice...

Spyros

# re: Unit testing with Cassini and NUnitASP – A complete example @ Thursday, June 14, 2007 5:07 AM

Nice!

Nektarios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Thursday, June 14, 2007 10:54 AM

Cool...

Nickolas

# re: Unit testing with Cassini and NUnitASP – A complete example @ Thursday, June 14, 2007 11:40 AM

Nice...

Georges

# re: Unit testing with Cassini and NUnitASP – A complete example @ Thursday, June 14, 2007 9:12 PM

Nice!

Angelo

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 15, 2007 12:27 AM

Interesting...

Epaminondas

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 15, 2007 9:52 AM

Sorry :(

Makis

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 15, 2007 11:07 AM

Nice...

Lefteris

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 15, 2007 5:50 PM

Nice...

Kostas

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 15, 2007 8:20 PM

interesting

Alexios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 16, 2007 7:41 AM

Cool.

Herakles

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 16, 2007 12:07 PM

interesting

Michalis

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 16, 2007 2:10 PM

Nice...

Kristion

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 16, 2007 2:44 PM

Cool.

Lefteris

# re: Unit testing with Cassini and NUnitASP – A complete example @ Sunday, June 17, 2007 6:59 AM

interesting

Evripides

# re: Unit testing with Cassini and NUnitASP – A complete example @ Monday, June 18, 2007 4:23 AM

interesting

Athan

# re: Unit testing with Cassini and NUnitASP – A complete example @ Monday, June 18, 2007 6:03 AM

Cool!

Gondikas

# re: Unit testing with Cassini and NUnitASP – A complete example @ Monday, June 18, 2007 6:21 PM

Nice

Demetri

# re: Unit testing with Cassini and NUnitASP – A complete example @ Monday, June 18, 2007 9:09 PM

Nice!

Andreou

# re: Unit testing with Cassini and NUnitASP – A complete example @ Tuesday, June 19, 2007 9:03 PM

Nice!

Aiakos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Tuesday, June 19, 2007 9:10 PM

Cool!

Constandinos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Wednesday, June 20, 2007 5:27 AM

Cool!

Socrates

# re: Unit testing with Cassini and NUnitASP – A complete example @ Wednesday, June 20, 2007 1:59 PM

Cool.

Charilaos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Thursday, June 21, 2007 6:40 PM

Interesting...

Solon

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 22, 2007 8:07 AM

Cool.

Neophytos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 22, 2007 10:01 PM

Cool.

Sterghios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 22, 2007 10:53 PM

Cool.

Leo

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 23, 2007 5:12 PM

Nice!

Kostantinos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Sunday, June 24, 2007 1:00 AM

Cool...

Sergios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Sunday, June 24, 2007 11:45 PM

interesting

Marios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Monday, June 25, 2007 10:30 AM

Nice

Anastasios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Monday, June 25, 2007 10:58 AM

Nice

Sophocles

# re: Unit testing with Cassini and NUnitASP – A complete example @ Monday, June 25, 2007 1:08 PM

Sorry :(

Leonidas

# re: Unit testing with Cassini and NUnitASP – A complete example @ Monday, June 25, 2007 8:46 PM

Nice...

Kostantinos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Monday, June 25, 2007 11:38 PM

Interesting...

Stephanos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Tuesday, June 26, 2007 2:01 AM

Nice...

Evagelos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Tuesday, June 26, 2007 8:16 AM

Nice!

Manolis

# re: Unit testing with Cassini and NUnitASP – A complete example @ Tuesday, June 26, 2007 6:52 PM

Nice...

Michail

# re: Unit testing with Cassini and NUnitASP – A complete example @ Wednesday, June 27, 2007 1:22 AM

Nice...

Savvas

# re: Unit testing with Cassini and NUnitASP – A complete example @ Friday, June 29, 2007 11:24 PM

Cool.

Odysseus

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 30, 2007 2:31 AM

Nice

Tasos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 30, 2007 4:35 AM

Nice...

Epameinondas

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 30, 2007 6:52 AM

Interesting...

Ambrosios

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 30, 2007 11:00 AM

Cool!

Carolos

# re: Unit testing with Cassini and NUnitASP – A complete example @ Saturday, June 30, 2007 6:31 PM

Cool!