So I've been keeping up with the world of DNN and very excited about all the new capabilities and want to develop really good code for my DNN Modules. How better to assist that process than unit testing. Now, I've been searching for quite some time on how to
properly unit test DotNetNuke code, mainly with its talking to the data tier. Because of the provider model, DotNetNuke has to be up and running. So I was considering using Nunitasp, but it has it's share of downfalls and do not think it will work with with
DNN. I want to build the unit testing right off my controller class (following the module document guidelines on proper module development) and provide all sorts of tests to it as I build it. Regardless of the size of the app I think it should still go through
this kind of testing but do not know how to accomplish this. Can anyone recommend a way to unit test my PA's within DotNetNuke? Any help would be much appreciated. Thanks!
Nunit. We want to work unit testing into the core but it is hard to drop in these very important things when a community is behind you pushing for features. Not to mention there are tons of tests to write just to catch up on over two years of development. There
are some in the core that think we should move to TDD, me being one of them. (Test driven development) Right now I cannot give you much more information than this. I can say that we have gotten many things into place for all of this to be part of the core
process. As for DNN unit testing, we are still in the early phases of getting to a point to explain the process to all of you. If you do jump into this endeavor, I would love to hear any information you obtain.
OK... So I jumped into this endeavor. =). Which, I found suprisingly easy after I worked out all my dependency issues (bah!) Now, I clearly cannot take a majority of the credit on this, I just simply finished a thought of someone else and applied it to DotNetNuke.
So I find this gem of an article by Scott Hanselman. http://www.hanselman.com/blog/PermaLink.aspx?guid=944a5284-6b8d-4366-81e8-2e241401e1b3 Now, its written in C#, but I went ahead and converted that over to VB. And tweaked an issue I was having with a file
buffer (bug in streamwriter?). But the point of the article is using cassini to test web projects. Now whether or not I need that for the pure unit testing is unknown. I'm going to go ahead and say "no" because we can create app domains on our own, which is
really what my biggest hangup was. Why? Configuration file, I wanted to make it so I didn't have to worry about any changes to the core or anything special in my code to make this unit testing worked. Regardless, It's working for me right now, and that makes
me happy... So if its not broken... don't fix it. So I took Scott's idea of creating embedded resources in my test harness. Which I then extract with a modified version of his ExtractResource and place it in proper directory. I put the SiteUrls.config and
Web.config of my development DotNetNuke 3.0.8. I then told NUnit to use Web.config as its configuration file for the tests... That was it. At that point, I just refernce my controller class and run my tests through there. Perfect! As I investigated the Framework
code for creating data objects (which I see is dependent on naming convention) I realize that I never do anything with aspx's or the user controls themselves so the use of cassini is kinda futuile. unless you want to use scotts method and request a page and
test for conditions. But you could use NUnitASP for that too, and perhaps a little more what you want on the UI side. The beauty is, nothing has to change. The way DNN is written (regardless of the provider model) lends itslef to perfect unit testing with
Nunit (thank you appdomain and setting config file for it!!!) It's just seems like a much bigger challenge than it really is.. I'm still new to this, but this is at least what I've seen.. HTH, Chris bTW, here is the modified extract resources code [code] Private
Function ExtractResource(ByVal pFilename As String, ByVal pDirectory As String, Optional ByVal pNamespace As String = "") As String Dim a As System.Reflection.Assembly = a.GetExecutingAssembly Dim filePath As String = String.Empty Dim path As String = String.Empty
Dim stream As stream Dim outfile As StreamWriter Dim infile As StreamReader Dim sTemp As String stream = a.GetManifestResourceStream(pNamespace & pFilename) If Not stream Is Nothing Then filePath = System.IO.Path.Combine(pDirectory, pFilename) path = filePath
outfile = File.CreateText(filePath) If Not outfile Is Nothing Then infile = New StreamReader(stream) If Not infile Is Nothing Then sTemp = infile.ReadToEnd() outfile.WriteLine(sTemp) outfile.Flush() End If End If outfile.Close() stream.Close() extractedFilestoCleanup.Add(filePath)
End If Return filePath End Function [/code]
OK... So I jumped into this endeavor. =). Which, I found suprisingly easy after I worked out all my dependency issues (bah!)
what kind of dependecy issuses did you have, and how have you solved them ? we are having some dependency issues with DotNetNuke.WebUtility (Error: The dependency 'DotNetNuke.WebUtility' could not be found) and currently we are out of ideas on how to solve
this. any ideas ?
I only ran into a few dependecy issues, none with DotNetNuke.WebUtility but with a differnet one. To resolve, I have a centralized library repository on a shared drive that I use. I pass the directory as a parameter from CCNET to NAnt for what directory to
look in using the flag. I copied all my other required assemblies to this directory and everything was good. I didn't use DotNetNuke.WebUtility in my module. I know that is a dependency of DotNetNuke.but that shouldn't matter at compile time unless you directly
reference it.
bump with an update. So I have been working more with unit testing my PA's. I struggled to get the nunit-console app working perfectly with config files, the gui works great but console would never be able to read config sections. After searching for awhile,
found this tool called mbUnit. (http://mbunit.tigiris.org) It will run any NUnit tests as well as its own and offers a lot more features. Anyways, I had a lot less trouble getting the dotnetnuke config file to work using this than I did with nunit. Still working
on getting something solid together.. but so far, mbUnit looks like the next generation of unit testers, and could offer a lot of promise to DNN's future. Nunit documentaiton is still better though. -Chris
AnyUserNameW...
Member
610 Points
124 Posts
Unit testing PA's with DNN
Jan 14, 2005 09:46 PM|LINK
thecrispy1
Star
12167 Points
2434 Posts
MVP
Re: Unit testing PA's with DNN
Jan 15, 2005 03:58 PM|LINK
AnyUserNameW...
Member
610 Points
124 Posts
Re: Unit testing PA's with DNN
Jan 15, 2005 07:19 PM|LINK
thecrispy1
Star
12167 Points
2434 Posts
MVP
Re: Unit testing PA's with DNN
Jan 17, 2005 02:35 PM|LINK
Vladan Strigo
Participant
1011 Points
222 Posts
Re: Unit testing PA's with DNN
Jan 26, 2005 09:35 AM|LINK
AnyUserNameW...
Member
610 Points
124 Posts
Re: Unit testing PA's with DNN
Jan 26, 2005 11:45 AM|LINK
AnyUserNameW...
Member
610 Points
124 Posts
Re: Unit testing PA's with DNN
Mar 05, 2005 06:34 PM|LINK
Vladan Strigo
Participant
1011 Points
222 Posts
Re: Unit testing PA's with DNN
Sep 12, 2005 09:44 AM|LINK
Hi AnyUserName,
Would it be possible for you to write a small howto on this thread about your implementation of unit testing in DNN ? (with mbunit)
rpredmond
Member
155 Points
31 Posts
Re: Unit testing PA's with DNN
Oct 17, 2005 10:10 PM|LINK
AnyUserNameW...
Member
610 Points
124 Posts
Re: Unit testing PA's with DNN
Oct 17, 2005 10:56 PM|LINK
Yeah. Sorry I didn't mean to ignore this thread. I wasn't getting replies to my email for some reason. Happened to be browsing and saw this.
But yes, I'll put together a little How-To. Gimme a day or so.
-Chris