How apply Unit tests in ASP.NET webforms - asp.net

I'm developing a website in asp.net webforms with 3 layers; UI, BLL and DAL
The website is already developed, but i like have more control about the unit tests of each form
Pass specific values at specific inputs for i see, if application survives or not.
I already study about NUnit but in webforms in UI layer how can apply these tests?
What i wnat is get some way to test UI (validations) without have to access to the BLL as i was an user.
I'm trying to add the Unit tests to my app but i not sure how to do it!
somebody can help my small-bigger problem?

You can add unit test to your UI using one of these tools
http://watin.sourceforge.net/
http://seleniumhq.org/
With both tools you can generate C# or VB classes that can be used by NUnit.
IMHO, UI test are not as reliable as the common unit tests. Bacause timing conditions you may randomly find that some test will fail.
I used both tools and I recommend selenium mainly because you can generate test that can be run against any browser.
Here an example how to use Watin with NUnit
http://www.codeproject.com/KB/applications/SimpleUITestHarness.aspx
And here a guide how to use Seleniun with Nunit
http://www.lostechies.com/blogs/agilecruz/archive/2009/02/10/how-to-configure-selenium-rc-for-use-in-c-nunit-tests.aspx

If I understand your question correctly, you're asking how to automate testing a WebForms UI. If I misunderstand, please correct this understanding.
Frankly, I don't think there is a good answer out there for this. There are two options, however, that work okay:
Visual Studio Test Edition
Telerik's Web Testing (both a free version and a version with a cost)

Related

Unit test Web Forms in Visual Studio 2012

I can't seem to find a walkthough/tutorial/blog posts etc on how to Unit test Web Forms in Visual Studio 2012. MSDN doesn't seem to cover it. The only thing I've been able to gleam from surfing for walkthrough's is that I need to have a clear separation of concerns to appropriately test an aspx.cs file. What am I missing? Are there any solid recent walkthrough's on how to implement simple unit testing in a Web Forms project?
Unit testing your code behind is practically impossible, since there's no context, no request and mocking all that is very difficult.
what you should do instead is separate your logic into another library and unit test that library. This would leave only view specific code in your code behind.
That code can then be tested through UI tests (with a tool like Selenium for example)

testing concept of first project

i am currently doing my functional specification document for my project. the only thing still missing is a testing concept. my project is all about an web app with which i can record and manage employee attendance in my ojt company. i am doing the app in asp.net web forms with c# as programming language. the ide i am using is vs for web 2012.
now i need to write a testing concept. i have already read a little literature about system and module tests. i have designed my app with a few model classes whose only methods are get() and set() methods. it may be that i will write a FEW methods where parameters are expected, for how much that matters.
i am little unsure about what tests i will be planning. could you maybe help me out here? a few crude examples would also be very helpful...
thanks
Here if u know about testing then there is no required of Test case & Test Plan.Its for only reference for Ur client.
First of all
U just do Functional testing, it will help to status of your project.
If every function is work properly then application will have no major problem.
Then just go through regression & Smoke testing
You should be doing following based on your requirements:
Unit Testing
Integration Testing
Regression Testing
Functional Testing
End to End Testing
Load Testing
Stress Testing
Performance Testing
Beta Testing
Security Testing
Usability Testing
Functional testing has many examples.
Like Login ,Add,Edit,Delete etc
Here u Just check these are functions working properly or not.
This is the basic thing in your Application

Which testing frameworks to use for asp.net websites and why

I use visual studio 2005 and now my team wants me to try my hand at some testing frameworks for asp.net websites.I'm completely new to testing. I want to know what kind of automated testing can I do.Can I test my business logic,Can I test my UI.I just started using NUnit and I am getting a hang of it. For Web UI testing I've tried Nunit asp.Somewhere I found about Selenium, which of this is better.Also is there an add-in to test Javascript code with NUnit.Is there an better alternative to NUnit. I kind of find difficult to figure out why should I use this tools.
One option is to use Watin: http://watin.sourceforge.net/
There is a nice Test Recorder, which allows you to record and save your tests.
The only problem I have had with it is that it doesn't always play well with Cruise Control as it loads a browser engine in the background. If the CI server is running in an environment without the correct browsers installed and enabled, then the tests will fail. In this case we ended up using HtmlUnit, which is a java app that runs on the Cruise Control server.
http://htmlunit.sourceforge.net/

How Testing relates to ASP.NET MVC/WEBFORMS Silverlight MVVM

Ive been learning MVC2 and MVVM lately and I think it works like this.
ASP.NET MVC2 - Can test the whole web site using unit tests
ASP.NET MVC2 + jquery web service calls - Can no longer just use MSTest unit test. What is the MS product to test the javascript side?
ASP.NET Webforms - Unit Tests are near impossible when the coder doesnt create the Webforms site with Testing in mind. Therefore Asp.NET web performance tests are the closest thing to testing that is realistic. Coded UI Tests are too trivial to really be useful for things like ASP.NET validators.
ASP.NET Webforms + jquery web service calls - Can only unit test the web service calls. Cannot use Web Performance tests because of javsscript calls. Need some sort of javascript testing framework.
Silverlight - No tests. Maybe Coded UI Tests.
Silverlight MVVM - Use silverlight unit test framework to test ViewModel similiar to MVC.
Silverlight MEF - How does MEF affect testing scenerios if at all ?
Is this accurate? Is there anything I am missing ?
I am trying to make a argument to the people in charge that we should use MVC over Webforms so that we can create automated testing. As it is we are doing Webforms all in one project and impossible to test so people just test off of manual scripts :(
Rather than specifying the reasons why you should use MVC over Webforms, I'd take a step back and sell the management team on why you should use unit tests. After that's sold you have a case of saying that MVC would allow you to do this more efficiently than webforms.
Are you looking at going the full TDD route, or just creating tests after? I'd highly recommend going down the TDD path even though it does have a steeper learning curve and will lessen your productivity while you are learning it.
Since you are already looking into testing, you probably know most of these, but I'll re-iterate some of the benefits:
Less defects get through to QA.
Tests can be created for issues that QA and customers find.
Designing for testing creates a more loosely coupled application which tend to be more maintainable.
Increased developer confidence when making changes leading to sustained productivity as the application code base matures.
Tests are great documentation for new developers joining the project, as they can see what's trying to be achieved.
Note: the cost of fixing a defect that has made it through to production can be up to 80 x the cost of finding and fixing it in the development and QA process (I'll try to find my source for that figure).
Unit testing is only one piece of the puzzle though, you'll also want to look at using a Continuous Integration server such as CruiseControl.NET to automate your builds and tests. This will make sure that everyone keeps the build in a working state.
For an existing Webforms project you might also want to look into the Web Client Software Factory. I've found it to be very useful for migrating legacy webforms apps over time, though it's a little more convoluted than MVC2.
I don't know about other technologies, but I can talk about using Silverlight with MVVM pattern. Using MVVM pattern along with command pattern, we have been able to unit test all of our C# code. I mean barring xaml code, we have a very high code coverage for our C# code. We actually use a modified version of MVVM wherein we also use a controller. If you ensure that you have no code in code-behind files, you can simulate button click/other such UI events. This is very useful for integration tests. We have found out that our pattern of MVVM along with controller and using command pattern facilitates unit testing.

Unit Testing the Web GUI

I recently heard a discussion in which TDD was the hot buzz word. Now according to one speaker, in order to test your behaviors you need to use MVC but on the other side its been said that TDD is an approach which can be adopted in any environment (as the discussion surrounding ASP.NET MVC or Web Forms). Another speaker claimed that if you put your behaviors in library or models then you can just test your repository or services in TDD and hence don't need to worry about testing HTML. How much TDD should cover in case of Web GUI testing or is it worth the effort?
I know sometimes we use the "next best thing" and carry it to the extreme, but it doesn't really benefit real development scenarios. So can TDD be applied to the UI?
EDIT:
I agree with you guys and that's also how I feel: if you really do TDD then you don't need to test your WEB UI front end, since the data that you're providing to it should be under your business/services/repositories layers which can be tested without a UI. So if you program your Web Forms application in such a way that your operations/behaviors are tied in with server side calls (like button click events although in my case they can be tested by calling lower level operations) you can have TDD in Web Forms. Thanks for your answers
I will be bold enough to say that if you need to unit test your GUI in order to get business logic, or integration testing done, then your design is lacking a clean separation of concerns. Both MVC and MVP are patterns that offer a clean separation of concerns so your UI can focus solely on presentation logic.
You do have both options in ASP.Net using either ASP.Net MVC, or WCSF (an MVP implentation using web forms).
That being said, you should still do GUI testing, but you have no need to do all this manually. Selenium Server, and Selenium Remote Control offer ways to do automated testing through the UI.
I agree with Josh here. Just getting going on SO, though, so I can't vote it up.
It should be noted firstly that testing your GUI is not unit testing. With clean separation of concerns, as Josh advocated, the GUI contains no business logic.
The logic that requires testing is encapsulated in one or more discrete libraries (or possibly in simple MVC controllers).
TDD refers only to logical code units, and one hallmark of solid TDD practice is that all of your logic code can be written and tested without any UI at all. In fact, tests are often written before the classes they will test. Once code is complete and all tests pass, the UI can be added to utilize the API hooks you've built, and that UI can be webforms, MVC, WPF, winforms, etc.
Testing on the UI that you'll do with a product like Selenium has more to do with acceptance testing or possibly integration testing.

Resources