NUnit errors testing asp.net mvc with linq app

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?
 
B

bruce barker

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)
 
C

Cowboy \(Gregory A. Beamer\)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top