NUnit errors testing asp.net mvc with linq app

  • Thread starter Thread starter Mark Elliott
  • Start date Start date
M

Mark Elliott

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?
 
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)
 
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! |
********************************************
 
Back
Top