Bloggin'bout Ivonna

Ivonna 2.1.7 is out! 

Thursday, May 12, 2011 9:26:42 AM

Finally I decided to release another, well, release in the 2.* series. This one is not only to restore the latest Isolator compatibility (which, by the way, fixes an annoying issue that prevented Ivonna from running with >net 4.0 sites), it introduces two methods (session.Get and session.Post) for MVC testing (really just simplification of existing functionality), and also session.Stub for simplifying stubbing dependencies in your tests. In short, these are not adding a significant piece of functionality, but rather something worth putting on the homepage as code examples.

Using AssemblyFixtureAttribute with Ivonna 

Thursday, August 19, 2010 8:18:16 AM

Typically, you want to run some initialization code for all your tests. Something similar to your Application_Start() method, e.g., building up NHibernate's SessionFactory, AutoMapper mappings etc. While most of it is still done in the Application_Start() method, you might want to do things differently. For example, you might need your configuration before the first Web request, or you might want to use a different database for automated testing.

In MbUnit, you can add a class and decorate it with the AssemblyFixtureAttribute, and the FixtureSetup decorated method will be run once before all tests. Remember, however, that if you want to use it with Ivonna tests, you should decorate the class with RunOnWebAttribute, just like a regular test class.

Ivonna 2.1.5 is out 

Monday, July 05, 2010 6:34:34 AM

Just uploaded the new 2.1.5 release, grab it here. Nothing new this time, just to make it compatible with the TypeMock Isolator 6.0.4.

All active development is currently done on the 3.0 branch, which is going to be more MVC-oriented (and let you extend it if you prefer other frameworks like Monorail, or FubuMVC, or Open Rasta). So, if you have a suggestion, just comment on this post, or use the forum.

Using #Ivonna and #CThru for testing Asp.Net MVC Views, part 2 

Saturday, June 26, 2010 9:05:00 AM

Well I finally got back to continue my ideas on using Ivonna to test MVC sites. This time I need to make sure that the authenticated user should see the list of her.. whatever. I won't bother you with much code this time (it's not that different from the previous part), instead, I'd like to return to the fundamental question of "How do I test this".

My first idea was, I've got something like a WebForms UserControl here, so I'd go for a RenderAction call. So, in my test I'll make sure that this method is called with proper parameters. If you're smarter than that, you can see that I'm tying my test to the implementation. Instead of "what", I'm testing "how". Should I change my implementation to calling RenderPartial or DisplayFor, my test breaks, although I still have my implementation done correctly.

To get it "right" (and you can guess there's no absolutely right way here), I think about what it means, "display a list of thingies". My guess is that it means two things, data and view, put together and displayed as part of the page. Now, getting the correct data is not the concern of this test (you should write a unit test here), but getting the correct partial View is the job for Ivonna. And after a quick Reflector session (or, better, using the built-in TraceAspect from CThru), we realize that all various implementations ultimately go through IViewEngine.FindPartialView. And all we have to do is spy on these calls, collect the arguments, and make sure that there's been a call to this method with a correct argument (that is, the path to your partial). This way, unless you move or rename the partial, the test stays green even if your implementation changes.

This CThru aspect can be useful in many other scenarios, so I'm going to include it in the next version of Ivonna, which will contain lots of other MVC related features.

Ivonna 2.1.4 is out 

Thursday, June 17, 2010 1:38:02 AM

This is a fix for the bug reported here. Go get it. Includes a new version of CThru.

Ivonna 2.1.2 is out 

Saturday, April 24, 2010 9:20:10 AM

I decided to postpone the new MVC related features to the next release, and just release the fix to the ASP.Net 4.0 issue mentioned in my previous post. The only other improvement is that the 400 Server Error thing is gone, and now we have a more informative exception here.

Ivonna and .Net 4.0 

Friday, April 23, 2010 2:02:33 AM

Due to some changes in .Net 4.0, your existing tests will probably break. What's worse, they're breaking with the uninformative "400 Server unavailable" message. A quick fix would be to use absolute paths in your tests, e.g., instead of "Default.aspx" you use "/Default.aspx".

This exception usually happens when the Asp.Net engine cannot create an instance of an HttpContext. However, the inner exception is not provided (who needs it anyway?), so you're left in the dark. In this case, the actual exception happens inside the HttpRequest.ClientFilePath property getter. It now allows only absolute paths for some reason.

The fix is going to be released at some point next week.

Using Ivonna and CThru for testing Asp.Net MVC Views, part 1 

Sunday, March 28, 2010 12:15:24 PM

Wait, isn't MVC testable by design? Yes, most of it is testable, but as for the Views, you have to resort to integration tests (which isn't bad by itself, but sometimes is not enough).

In my recent project, I needed to write a test verifying that if a user is not authenticated, she should see a login form and a registration form. Speaking in terms of implementation, this means that Html.RenderPartial should be invoked with paths to my partial views containing these forms. Looks like a good task for TypeMock Isolator, but I prefer working with CThru. Here's the test code (forgive me for not following the strict rules, such as one assert per test, this is just for clarity):

Imports WebTests.Infrastructure
Imports Ivonna.Framework
Imports MbUnit.Framework
 
Namespace Membership
    <TestFixture(), RunOnWeb()> _
    Public Class OwnersPage_NotLoggedIn
        <Test()> _
        Public Sub ContainsLoginPartial()
            'Arrange
            Dim spy As New RenderPartialSpy
            CThru.CThruEngine.AddAspect(spy)
            Dim session As New TestSession
 
            'Act
            session.ProcessRequest(New WebRequest("Owners"))
 
            'Assert
            Assert.Contains(spy.ViewNames, "~/Views/Account/Login.ascx")
            Assert.Contains(spy.ViewNames, "~/Views/Account/Register.ascx")
        End Sub
    End Class
End Namespace

The RenderPartialSpy class can be reused (this is why I prefer CThru), here's the code for it:

 
Imports CThru
Imports System.Web.Mvc.Html
 
Namespace Infrastructure
  Public Class RenderPartialSpy
    Inherits Aspect
 
 
    Public Overrides Function ShouldIntercept(ByVal info As CThru.InterceptInfo) As Boolean
      Return info.TypeName.Contains("RenderPartialExtensions") AndAlso info.MethodName = "RenderPartial"
    End Function
 
 
    Private _viewNames As New List(Of String)
    Public ReadOnly Property ViewNames() As IList(Of String)
      Get
        Return _viewNames
      End Get
    End Property
 
    Public Overrides Sub MethodBehavior(ByVal e As CThru.DuringCallbackEventArgs)
      Me.ViewNames.Add(e.ParameterValues(1))
      MyBase.MethodBehavior(e)
    End Sub
 
  End Class
End Namespace

Here I just set it to intercept all calls on the RenderPartialExtensions class with the method name "RenderPartial". When the call is intercepted, I save the value of the second argument (remember this is an extension method) in my list. At the Assert stage, I'll be able to retrieve all saved values and check them.

Ivonna 2.1 is out 

Sunday, February 21, 2010 8:48:33 AM

Much much later than promised, but finally the 2.1 is out.

The focus of this release is on AJAX support. While Ivonna still doesn't deal with client side stuff, you can now fake an AJAX request and test the server's response.

Let's see the code:

var session = new TestSession();
var result = 
session.ExecuteAjaxMethod(
"Page.aspx",
"MethodName",
new {name="John"});
Assert.AreEqual("Hi John!", result);

Note that I'm using an anonymous class object to pass the arguments.

The code above would work with JSON-formatted Web services as well (note that you wouldn't use SOAP formatted services with AJAX anyway). If you need to return a custom object, you can use a generic overload of the same method.

There's also another, simpler alternative for doing AJAX: UpdatePanel. While most serious developers frown upon it, it remains a nice option for doing it quick (and dirty) if the performance and traffic is not an issue. While there's not much you can test with it, Ivonna provides a way to execute a request coming from inside an UpdatePanel:

var session = new TestSession();
session.GetPage("HasUpdatePanel.aspx");
var response = 
    session.ProcessRequest
    (session.CreateUpdatePanelRequest
    ("Button1"));

That's all for AJAX functionality in the current release. I'd probably have to fix a few bugs or provide more options and better API in the future releases. Please give me some feedback in the Forums.

As for the optimization stuff, I already wrote about it in the previous post, so there's not much to add.

So, what's the roadmap for 2.2? I guess it's going to be extensibility. The code is complicated enough to introduce an IoC container (it's going to be StructureMap), and I'd like to open some possibilities for custom request and response types, as well as modify the initialization aspects for advanced scenarios. You are welcome, as always, to suggest an extension you want, and I'll make Ivonna flexible enough to satisfy your needs.

Notes on new performance enhancements in Ivonna 2.1 

Saturday, February 06, 2010 6:30:44 AM

Ivonna 2.1 is due this weekend, and while I've been testing the final bits, I noticed a bug which cannot be fixed without changing the overall architecture, so I decided to leave it and be clear about it.

One of the most annoying things about Ivonna was her bad performance on startup. Every time I needed to run a test, the Asp.Net engine cleared the temp folder and recompiled the whole site. It would take up to several minutes, depending on the number of pages. So, in the 2.1 release, I decided to stub the whole thing. The startup time dropped to several seconds, which is sort of acceptable (note that each test itself takes much less time to run).

Everything went fine until I put some code in an App_Code class, and Ivonna couldn't load it. It turned out that no changes in the App_Code folder could be recognized by the test. However, changes in the codebehind are recognized.

The workaround is, whenever you make a change to or create an App_Code class, be sure to delete the temporary site folder, which is usually under the C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\ folder.

Page 1 of 3 1 2 3 > >> 
Copyright 2008 by me

Site Map | Printable View | © 2008 - 2012 Your Company Name

Powered by mojoPortal | HTML 5 | CSS | Design by styleshout