473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

NUnit errors testing asp.net mvc with linq app

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/
Jun 27 '08 #1
2 2228
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/
Jun 27 '08 #2
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" <ya**********@hotmail.comwrote in message
news:op***************@aka-wk04.eastlink.ca...
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/
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sky Kim | last post by:
Hi, all. I've know NUnit for a while, now I try to use it. Most of application I develope is data base driven. I want to test data layer most with may input and checking the result, then compare...
7
by: Alvin Bruney | last post by:
I've a question on unit testing with NUnit. I'm sure I'm missing just a little thing here. Why doesn't NUnit allow me to test a routine with parameter in it like what i want to do is test ...
3
by: Ole Hanson | last post by:
Hi I am trying to engineer a way of testing that my logging framework is capable of writing to my eventlog. I want to include this test in my already existing NUnit tests - but I'm a little low...
5
by: Naveen Mukkelli | last post by:
Hi all, How can we use "NUnit" in socket programming. I mean, I'm writing a server program which accepts connection requests from the clients. I want to test the number of clients whenever a...
1
by: Justin D. Fisher | last post by:
Anyone out there use NUnit for unit level testing on VB.Net? I see lots of C# documentation out there but very little for VB.Net? Can anyone suggest some books or web sites that address this?
3
by: JJ | last post by:
Hi, In Nunit testing with asp.net are you guys creating a separate Test assembly for testing or integrating right in class themselves? Is anyone using a third party Unit Test addon for Nunit to...
1
by: MD | last post by:
Hello I work in a .NET environment and I am about to create a development strategy. As part of this I am looking at implementing a testing tool to fit in with an iterative approach and NUnit...
20
by: Parag | last post by:
Hi, I am trying to figure out best testing tool for my project. I have narrowed down my requirements to two tools NUNIT and VSTS unit. But I have used neither and I have to use only one of them....
5
by: Mike Hofer | last post by:
I need some advice, folks, and I'm hoping you can provide it. First off, a few disclaimers: 1.) I am an ardant advocate of code quality. Especially, my own. 2.) I am maintaining a massive...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.