Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > NUnit errors testing asp.net mvc with linq app

Reply
Thread Tools

NUnit errors testing asp.net mvc with linq app

 
 
Mark Elliott
Guest
Posts: n/a
 
      06-13-2008
Hi All,

I'm just playing with asp.net mvc and link-to-sql for the first time. I'm
using visual web developer 2008. I create the project fine, choose nunit
as my test framework in the wizard. Everything is fine, compiles and the
tests work fine on the basic application. However once I add some linq
things to it, and specifically the line:

WestoriaDataContext westoria = new WestoriaDataContext();

Now when I try to run tests in nunit it fails with a bunch "object
reference not set to an instance of an object" errors. The site itself
runs fine, the code is fine from what I can tell. Anybody using nunit
experience this or know what I might be missing?

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      06-13-2008
unit tests do not use web.config, but rather the application config of the
unit test so the connection strings are not set. also in unit tests, the
response is not defined..

you should supply factories for all system objects, and create mock objects
to be used by the unit tests.

-- bruce (sqlwork.com)


"Mark Elliott" wrote:

> Hi All,
>
> I'm just playing with asp.net mvc and link-to-sql for the first time. I'm
> using visual web developer 2008. I create the project fine, choose nunit
> as my test framework in the wizard. Everything is fine, compiles and the
> tests work fine on the basic application. However once I add some linq
> things to it, and specifically the line:
>
> WestoriaDataContext westoria = new WestoriaDataContext();
>
> Now when I try to run tests in nunit it fails with a bunch "object
> reference not set to an instance of an object" errors. The site itself
> runs fine, the code is fine from what I can tell. Anybody using nunit
> experience this or know what I might be missing?
>
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
>

 
Reply With Quote
 
 
 
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      06-14-2008
What are you testing? or perhaps How are you testing it?

In general, you should be testing the controllers, to ensure correct view,
viewdata, etc. You should also test any components you have added, along
with your business logic, which should be in libraries. If your libraries
call data, etc., you should mock it.

As to your particular error, it looks like you are instantiating data, which
probably pulls from the web.config. This is not unit testing, it is
integration testing. nUnit will not read the web.config, so the data
contexts will fail every time unless you use something like a mock object.
nUnit has rudimentary mocks, mbUnit uses RhinoMocks.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

********************************************
| Think outside the box! |
********************************************
"Mark Elliott" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Hi All,
>
> I'm just playing with asp.net mvc and link-to-sql for the first time. I'm
> using visual web developer 2008. I create the project fine, choose nunit
> as my test framework in the wizard. Everything is fine, compiles and the
> tests work fine on the basic application. However once I add some linq
> things to it, and specifically the line:
>
> WestoriaDataContext westoria = new WestoriaDataContext();
>
> Now when I try to run tests in nunit it fails with a bunch "object
> reference not set to an instance of an object" errors. The site itself
> runs fine, the code is fine from what I can tell. Anybody using nunit
> experience this or know what I might be missing?
>
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WebForms X MVC? Why MVC? Give me reasons to migrate my web apps to it please. Pros x Cons! Thanks! Paulo ASP .Net 3 12-04-2008 03:00 AM
Linq or not Linq George ASP .Net 4 11-05-2008 04:53 PM
differences between Spring WebFlow,Spring MVC,and String Portlet MVC? rmn190 Java 2 01-10-2008 02:27 AM
Unit Testing ASP.NET 1.1 w/NUnit Mike Hofer ASP .Net 5 03-30-2007 07:40 PM
NUnit Testing JJ ASP .Net 3 12-20-2005 02:53 PM



Advertisments