Implement Unit Testing on a legacy web site - vb.net

I downloaded nUnit and TestDriven.net. I have a legacy Web Site application and I would like to implement some unit testing. I created a class in the app_code folder and added Imports NUnit.Framework etc... After writing a basic test, I get the "Can't execute tests in 'Web Site' application." error. I guess the Web Site project is not supported. Converting to a Web Application is not an option at this time. I have Visual Studio Test Edition, so I tried that route. I created a test project, wrote a couple tests in my test class etc... only to find out I cannot reference the classes in the app_code folder of the Web Site project. Can anyone out there give me some pointers??? Am I doing something wrong. I am pretty new to TDD. I just want to properly implement a bit of testing on this application.
Thanks In Advance,
~ck in San Diego

Create a separate project for unit tests, especially if you are using a web site.
You should probably not be unit testing the classes in your web site. Rather, any classes you'd want to unit test, should probably not be in the web site. Rather, they should be in a class library project that is referenced by the web site.
This is yet another reason to not use web sites: they do not compile until they are used, so there is no compiled version of the code in app_code for your test project to test.
Web sites should be used for nothing other than simple web sites. Anything else is more sophisticated than they were intended to handle. Use a Web Application Project instead (but still keep must interesting code out of the project).

I think John Saunders has sound advice. You want to try the web site a presentation layer and isolate the classes that comprise the business logic into a separate library for testing. This allows you to focus solely on the processes that the classes are intended to implement.
So you know I started out TDD with nUnit then used the MS Test suite for a major project. I would chose nUnit over MS as it was much faster.

Related

How can I decide automation feasibility for web application?

Guys I need to decide feasibility of automation testing in web application. Application is developed in c#.net. Can any one guide me about factor which I need to consider for automation testing. I have some basic knowledge of Selenium WebDriver using Java, can I test web application using it? This application is leasing application it contains many calculations to calculate plan. Application also contains many reports as well as graphs to analyse enquiries as well as results.
I suggest some basic links to start with
http://www.softwaretestinghelp.com/choosing-automation-tool-for-your-organization/
http://searchsoftwarequality.techtarget.com/answer/How-to-choose-the-best-software-test-automation-tool-for-your-team
http://www.xoriant.com/blog/software-testing-and-qa/selecting-right-test-automation-tool.html
Your approach is definitely good. You can develop a ASP.NET MVC web application in C#, setup some core business logic by classic unit test and make integration test using selenium driver.
I suggest following that you first create a lightweight skeleton of the project containing:
git repository
ASP.NET web application
continual integration with build machine (use TeamCity or similar software)
unit test testing your core business logic
integration test written in selenium driver using C# running for all common browsers with good selenium support.
Check that with every commit following happen:
build is triggered
deployment package is created
unit test are triggers
integration test using selenium driver are triggers
all reports are collected
test results are stable (same results for same build number for repeated testrun)

Getting coverage using OpenCover for Selenium tests

The background:
We have a project starting a service that gets controlled from the web interface GUI.
We're not using a specific (from a commercial point of view) web server, but an in-house created wrapper around the windows service that manages all the web interface interactions.
What we have:
Now we've started using Selenium & MSTest for testing the web interface and we're trying to get a coverage for these kind of tests, and OpenCover seemed to do the deal. The problem is that is not (or we're doing something different or wrong).
The only code coverage that I'm not getting is the one for the method used to start the windows service and all others that get called in the process (since I have all access to all the PDBs too), but afterwards nothing is covered, based on the action that take place from the Selenium's interaction with the browser.
Any hints/ideas or maybe other tools that are able to do the job (if even possible) are appreciated.
If you're running an ASP.net app, you're going to need to attach OpenCover to IIS or IISExpress to get accurate code coverage with selenium. That makes it a little hard to use MSTest with. You may want to consider moving as much logic into your services, and write unit tests against those.
Here's a quick example hot to attach open cover to IIS
OpenCover.Console.exe -target:C:\Windows\System32\inetsrv\w3wp.exe -targetargs:-debug
-targetdir:C:\Inetpub\wwwwoot\MyWebApp\bin\ -filter:+[] -register:user

Easy way to have a VB.Net WindowsForms application work as a web app?

I have made a small text based game using VB.NET in a Windows Forms application but it seems that people are a bit hesitent when it comes to downloading exe files. What would an easy way to have it work as a web application without having to rewrite the entire code?
There isn't an "easy" way to turn it into a web application. You can take all of your logic and put it into libraries (Class Library), but you'll need to write new front-end code for both the desktop and web.
If you are wanting the web to accept user input and such without constant reloading, you'll also need to make a web service to talk to using jQuery or the like.
For what it's worth, if anyone is hesitant to download an EXE, then they don't need it. I used to publish installations for VB6 applications on my website years ago, and I had downloads and referrals from all over the place, including educational institutions.
Also, if you are direct linking to an EXE, consider packaging it up in a ZIP along with a readme file.

Jakarta Cactus alternate?

Greetings, we have a project with loads of beans, JSP and etc. There is a desperate need for performing automated tests in our environment (we use Maven). Now, we can easily write tests for database project layer, for various security utilities we implemented. But the JSP pages remain untested.
I searched for utilities for server-side testing and Cactus seems the best option. However, according to their changelist, their last release is 1.8 and it was released more than two years ago!
So the question is - what happened to Cactus, is it still developing or what? And what are the recent alternates for Jakarta Cactus (if any exists)?
I've used a combination of Spring, JUnit and HttpClient with some success in recent projects.
Apache HttpClient provides a powerful and flexible API for constructing and sending http requests into your application. It cannot replicate a web browser, say by running client side scripts, however if there is sufficient content within the resulting http responses (headers, URI, body), then you can use this information to traverse pages within the application and validate the behavior. You can post forms, follow re-directs, process cookies and supply the inputs into your application.
JUnit (junit.org) drives the tests, invoking a series of pages with HttpClient and can be deployed alongside the application, run standalone with ant/maven, or run separately inside your IDE.
Spring (springsource.org) is, of course, optional as you may not be using it for your project. I've found it useful to stub/mock out parts of the application, such that I can isolate specific areas, such as front-end controllers, through to the business logic, by substituting the DAOs to return specific data values. It provides an excellent Test Context Framework and specialized TestRunners that hook in well to testing frameworks like JUnit (or TestNG if you prefer).
Cactus served as a good server-side testing framework in the ejb2 ages and but it's not supported anymore.
You can use combination of both Mock testing (fine-grained) and In-Container testing (coarse-grained) strategy to test your application completely.
Mock Testing Frameworks : Mockito, Jmockit, EasyMock etc..
Integration Testing Frameworks (Java EE) : Arquillian, Embeddable API, etc..
I prefer Mockito and Arquillian for server-side testing.
How about Arquillian? I haven't used it and it doesn't even have a stable version yet, but at least it's in active development.
You might want to try selenium. That with jBehave is a good combination I'm finding. And the more support for both those projects, the more they will not go defunct (like cactus).

Advantages of Powershell for web-ui testing?

I am working on a commercial project which is a web-based app which will be bundled with an app/web server (JBoss), which is deployed, with the web app files, at runtime.
I've seen links about how Powershell can do UI testing. Is there any advantage in Powershell for web-testing as opposed to Selenium or VS2010's coded UI tests? (Selenium has poor documentation, which is in Powershell's favour, but I am interested in more functional reasons).
Thanks
Powershell will give you advantage if you need to manipulate something else than a browser/webpage/webapp. With Powershell you can do something with OS, applications, things outside the browser.
If you don't need to do that, if you want to automate only web based app, than I would suggest using web specific tool. Selenium is nice, tests in MSVS2010 are great. If you prefer coding try WatiN for .net, and WatiJ for java. All of them will run smoothly not only inside IDE, but also on CI server.