Microsoft MVP Logo

    <p>Since the time I started using unit testing within my projects (specifically with NUnit &amp; TestDriven.NET), the one thing you find very quickly, is that it&rsquo;s not easy to test your presentation layer.&nbsp; Sure there are pricy products from people like Mercury, but I&rsquo;m looking for something a little more affordable around NUnit&rsquo;s price point (see: FREE).&nbsp; </p>
    <p><strong>Automated Web UI Testing</strong></p>
    <p>One of the most common suites I saw that&rsquo;s used is NUnitASP.&nbsp; I attended a BOF at TechEd USA where it was discussed, but, like <a title="" href="">David Strommer</a>, I didn&rsquo;t get a feel like this was an ASP based solution&hellip; rather an HTML/HTTP solution.&nbsp; The tests you write seemed to only interact with the resulting HTML that reaches the client over HTTP&hellip; it makes no distinction between the different web technologies (static HTML, ASP, ASP.NET, JSP, etc).&nbsp; I&rsquo;ve tinkered with NUnitASP and so far I&rsquo;m not so thrilled.&nbsp; I&rsquo;d like to see more of my tests integrated within NUnit.&nbsp; At any rate, the presenter, <a href="">Jonathan Cogley</a>,&nbsp;of the BOF session has some good NUnitASP helper stuff on his site as <a href="">Darrell Norton pointed out recently</a>.</p>
    <p>While on vacation, I saw <a href="">Scott Hanselman&rsquo;s post about Ruby and Watir</a> (<em>pronounced wah-ter</em>), where he went into detail about integrating them within NUnit&hellip; a very detailed post as well!&nbsp; Looks promising&hellip; and if Scott is sold as he stated in his post, then it&rsquo;s definitely worth a look.&nbsp; Here are some links where you can get <a href="">Rudy</a> and <a href="">Watir</a>, both available at <a href="">RudyForge</a>.</p>
    <p><strong>Automated Managed Web Application UI and Component Testing</strong></p>
    <p><em>When I say &ldquo;managed web application&rdquo;, I&rsquo;m referring to something like <a title="" href="" target="_blank">SharePoint</a> or <a title="Microsoft Content Management Server" href="" target="_blank">MCMS</a> which use IIS ISAPI filters to analyse, build, and render content based off the URL requests.</em></p>
    <p>Another thing that has me challenged is testing your classes that extend objects from managed applications.&nbsp; As I mentioned previously above, if I was just interested in testing the presentation layer of my code in managed web application environments, I can just use an HTML/HTTP suite like NUnitASP, Rudy, or Watir.&nbsp; That&rsquo;s fairly straightforward.</p>
    <p>However there&rsquo;s another case I&rsquo;d like to test.&nbsp; What about the cases where you have an object that inherits another object that requires an HttpContext&hellip; but like MCMS, you use an extended HttpContext (such as CmsHttpContext)?&nbsp; Let&rsquo;s take a Custom Placeholder Object as an example.&nbsp; When you create a custom placeholder, you can inherit the the BasePlaceholder object which has five methods to override.&nbsp; I&rsquo;d like to be able to instantiate an instance of the object and run some tests on it.&nbsp; How would you go about it in this case?&nbsp; Well, I obviously can&rsquo;t just run a test directly on the object because it needs to be run through the MCMS ISAPI filter.&nbsp; </p>
    <p>One way you could test it was to manually (or programatically), build up a new posting, add some content, save it (and optionally approve it), then use one of the HTML/HTTP suites to test the resulting rendered HTML.&nbsp; But that&rsquo;s quite a bit of work&hellip; I think it should be even easier.&nbsp; </p>
    <p>Another approach is to seperate as much code as possible&nbsp;into another class.&nbsp; The CMS overloaded methods would then just be treated as wrappers calling the methods in your other class.&nbsp; It&rsquo;s the same approach that many (including myself) use when they implement event handlers; you don&rsquo;t put all your logic inside the actual event handler&hellip; your handler simply makes a call to a private method in the class.&nbsp; Then you don&rsquo;t run any tests against your custom placeholder.&nbsp; Yes, it&rsquo;s a risk you&rsquo;re not taking into account, but it&rsquo;s quite mitigated in my mind as long as you thoroughly test your wrappers.&nbsp; This method is working out quite well for me&hellip; so far.</p>
    <p>However, it&rsquo;s not nearly as nice as testing the object directly.&nbsp; So I blog aloud &ldquo;what are other people doing in situations like this?&rdquo;&nbsp; Anyone know how VS <a title="" href="" target="_blank">.NET</a> 2005&rsquo;s unit testing framework addresses this&hellip; if at all?</p>
Comments powered by Disqus