Page 1 of 1

Creating a new user with NUnit

Posted: Tue Sep 23, 2008 11:39 am
by MarkI
Hi,

I've added an NUnit project to our AbleCommerce solution. Right off the bat I'm running into issues trying to simply create a user. Has anyone tried this?

Here is what I am calling:

Code: Select all

//...
User user = UserDataSource.CreateUserInstance(Guid.NewGuid().ToString());
//...
In the file I am "using CommerceBuilder.Users;"

However, I am consistently getting the following error on the line above:

Code: Select all

"System.Configuration.ConfigurationErrorsException : Unable to open configSource file 'App_Data\ablecommerce.config'."
I have tried copying this file into the bin directory of NUnit's project, which is the typical thing to do for config files and NUnit, but with no luck.

Any help/suggestions/pointers is greatly welcome.

Thanks,

Mark

Re: Creating a new user with NUnit

Posted: Tue Sep 23, 2008 2:00 pm
by afm
First try creating a directory called App_Data under bin (this is just a wild guess). If that does not work, then use FileMon to see where it is looking and then put the file there.

Re: Creating a new user with NUnit

Posted: Wed Oct 01, 2008 11:52 am
by MarkI
Thanks Andy,

Your post helped me solve it. I tried FileMon, but that has been replace by "Process Monitor" for use in Vista. Process Monitor helped me discover that it is looking for App_Data under bin\Debug.

For those who attempting using NUnit (which I highly recommend) with AbleCommcerce, the following line of code requires that both the ablecommerce.config and the database.config must be copied to <your nunit test project folder>/bin/Debug/App_Data.

Code: Select all

User user = UserDataSource.CreateUserInstance(Guid.NewGuid().ToString());
Thanks,

Mark

Re: Creating a new user with NUnit

Posted: Wed Oct 01, 2008 9:31 pm
by afm
Thanks Mark. That would be a handy tip for the wiki.

Re: Creating a new user with NUnit

Posted: Wed Oct 01, 2008 10:32 pm
by AbleMods
What's NUnit??

Re: Creating a new user with NUnit

Posted: Wed Oct 01, 2008 10:41 pm
by Shopping Cart Admin
Hello Joe,

Never heard of google :)

http://www.nunit.org/index.php

What Is NUnit?

NUnit is a unit-testing framework for all .Net languages. Initially ported from JUnit, the current production release, version 2.4, is the fifth major release of this xUnit based unit testing tool for Microsoft .NET. It is written entirely in C# and has been completely redesigned to take advantage of many .NET language features, for example custom attributes and other reflection related capabilities. NUnit brings xUnit to all .NET languages.

Re: Creating a new user with NUnit

Posted: Thu Oct 02, 2008 6:16 am
by AbleMods
I don't really know what XUnit is any more than NUnit.

But I've recently learned about something called Google so I'll go see what it does on my own.

Re: Creating a new user with NUnit

Posted: Thu Oct 02, 2008 9:35 am
by Shopping Cart Admin
Hello Joe,

I'd heard of if a number of times, but never checked into until this post.

Re: Creating a new user with NUnit

Posted: Thu Oct 02, 2008 2:39 pm
by afm
I've been using NUnit for a couple of years to automate regression testing (i.e. I can run the tests to make sure that my existing code still works the way they are supposed to after fixing a bug or adding a feature). It has become much more popular lately with the rise in test driven development (TDD), where you write the test first (i.e. The test defines what the feature is supposed to do, then you write the code. You know the code is "done" when the test passes.).

In TDD it is important that the tests--which define the features--are easy to write and clearly define the feature. For the most part, NUnit meets those requirements. For example,

Code: Select all

[Test]
public void New_Customer_Should_Have_Empty_Names()
{
    Customer customer = new Customer();
    Assert.AreEqual(customer.FirstName, string.Empty);
    Assert.AreEqual(customer.LastName, string.Empty);
}

Re: Creating a new user with NUnit

Posted: Sun Oct 05, 2008 10:15 am
by AbleMods
Does it automate (i.e. simulate) the user input?

Re: Creating a new user with NUnit

Posted: Sun Oct 05, 2008 10:54 am
by afm
SolunarServices wrote:Does it automate (i.e. simulate) the user input?
Depends on how the app is written. For AC7, no. For that you need one of the GUI testing frameworks like Watir.

For apps that follow a strict model-view-controller architecture, raw user input is typically passed to the controller. And you can test the controller's behavior to user input using NUnit.

AC7 does some user input processing in the "view" (the webform or it's code-behind file). To test that you need to pretend to be an actual user clicking on buttons and entering text. That is what Watir does.

Re: Creating a new user with NUnit

Posted: Mon Oct 06, 2008 9:40 am
by MarkI
SolunarServices wrote:Does it automate (i.e. simulate) the user input?
NUnit and the concept of unit testing doesn't necessarily cover user input. Unit testing is meant to test an application's methods and class design by verifying that what you wrote does what you intend it to do. Unit testing typically falls under the test driven development methodology whereby the tests are actually written before the code. Once your code passes the unit tests then the idea is you can feel confident that your code not only works, but also does what you want it to.

With regard to user input, unit testing does not do any user simulation. However, you will most certainly create some test data with which to run your unit tests, so that may help you some.

If you google UNnit and tdd (for test driven development) you will find many resources. A quick search turned up this article which does a decent job of explaining the process.

Mark Iverson
Iverson Software

Re: Creating a new user with NUnit

Posted: Thu Oct 09, 2008 3:27 pm
by Logan Rhodehamel
Early AC7 development goal was to make extensive use of NUnit. We couldn't quite make it happen the way I wanted, and then the reasons for the goal changed. In AC5 we had a lot of hand written code that contained simple errors - TDD would have caught those. In AC7, the bulk of our code is generated. The errors we were looking to trap were already elminated.

Another tool that is helpful (if dated) is Microsoft Web Application Stress Tool. I use this to simulate user input somewhat. Scripts can actually be quite complex if you make use of variables.

But in the end, we haven't found a tool that can replicate the efficiency of human testing for the front end scripts.

I am sure additional automated testing (perhaps NUnit or a combination of tools ) will return to the AC7 goal sheet. Some things are awful to test (e.g. discounts) but often have to be retested due to other changes. Since we can determine the expected results, I am looking to automate some of these time consuming tests.