473,657 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:

WestoriaDataCon text westoria = new WestoriaDataCon text();

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 2234
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:

WestoriaDataCon text westoria = new WestoriaDataCon text();

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**********@h otmail.comwrote in message
news:op******** *******@aka-wk04.eastlink.c a...
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:

WestoriaDataCon text westoria = new WestoriaDataCon text();

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
1767
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 with database if it returns right value or not. To do so, I need to save all inputs and results as development, debugging goes on.. But, NUnit doesn't seem to support it. and It require wrong Test coding.
7
1444
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 private string testme(string test) and put my test code in there. So why the emphasis on having me write a specific routine with a void return type and an empty parameter? Is it because its forcing me to write a routine to call testme to make sure it...
3
3209
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 on ideas as how to assert that I actually did write to the eventlog successfully. Naturally I want this assertion without having to open my eventlog and visually verify the writing.
5
4637
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 new connection is established. My Server code is : ---------------------------------------------------------------------
1
2099
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
1811
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 test asp.net? What is it called, and how do you like what you are using? Any problems testing user controls with it? Any body have any real world examples of Nunit with asp.net that they can share. Just a skeleton layout would suffice. How many...
1
1793
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 seems to be the logical choice. Although it works well with very simple classes, it seems to struggle when you are confronted with anything substantial - eg an application that accesses/updates an RDBMS. For instance :-
20
2013
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. Hence can someone who has used them before share his/her experience on them so that I can get a better idea and make a proper choice ? Any link or suggestions are also welcome. Thanks and Regards, Parag
5
1483
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 ASP.NET 1.1 code base that has no unit tests built for it with NUnit or any other testing framework. 3.) Moving to .NET 2.0 and VSTS is not an option.
0
8411
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.