Archive | Guideline RSS feed for this section

Unit Testing and Test Automation in VS2012 Part 1: Running NUnit natively in Visual Studio

4 Jul

One of the most criticized features of Visual Studio ever since it came out has been the ability, or lack and inadequacy thereof, of the IDE to integrate third-party unit testing libraries into it. MSTest was not only too late but was also too lame — it wanted users to rely on automatically generated tests put up after code has already been written. This runs so counter to the tenets of Test Driven Development that MSTest was simply ignored, and many developers came up with ways to hack third party unit-testing frameworks like NUnit, MBUnit, xUnit and so on for their .NET projects. Inevitably, Microsoft and MSTest ended up being vilified by the believers of TDD.

With Visual Studio 2012 Microsoft provided a means of using frameworks like NUnit and Selenium to actually be run within its IDE, in a tightly integrated way, and in turn, the ability to code test-first.

Let’s talk about how to make that happen.

Setting up the NUnit Test Adapter

First in our agenda is to wire Visual Studio 2012’s testing framework to NUnit. To be able to do this we need to download and install the NUnit Test Adapter extension, which we will do via Visual Studio’s “Extension Managers” feature:

  1. With Visual Studio 2012 started, go to the Tools Menu and click on Extensions and Updates
  2. On the left tab click on “Online” and on the Search field on the upper right type in “NUnit Test Adapter”. You will need an internet connection for this to work.
  3. When the NUnit Test Adapter item appears click the “Download” button. Once the download is complete follow the instructions to install the NUnit Test Adapter
  4. At the bottom of the window you may be asked to click “Restart Now” to allow the newly installed components to take effect within Visual Studio 2012.

Once you’ve finished this Visual Studio 2012 is now ready to run NUnit tests within the IDE.

Creating your first NUnit test project

Let’s now create our first NUnit test project.

  1. Go to File -> New -> Project and under Visual C# choose “Class Library” and rename to “NUnitTestDemo”. You may also want to rename your “Class1.cs” into something more sensible.
  2. In the Solution Explorer right-click on references then click “Manage NuGet Packages”.
  3. On the left tab click on “Online” and then on the Search field type “NUnit” this time. When the result appears click “Install”.

All the relevant classes required for NUnit should now be included in the project — it’s now time to write some unit tests!

Our bare code so far looks like this (I’ve renamed the project “NunitTestDemo” and the default class “FirstUnitTest”):

1
2
3
4
5
6
7
8
9
10
11
12
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NunitTestDemo
{
    public class FirstUnitTest
    {
    }
}

To check if NUnit works on Visual Studio let’s try adding bits of code and one dummy test:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace NunitTestDemo
{
    [TestFixture]
    public class FirstUnitTest
    {
        [Test]
        public void TrueTest()
        {
            Assert.IsTrue(true);
        }
    }
}

To run this test, click on the Test menu, Run, then All Tests. You could also use the shortcut Ctrl-R, then A.

The test result under the new “Test Explorer” tab will look like this:

Details like the name of the tests and execution times of both individual and all tests appear in this tab.

Let’s add a failing test just to see what it looks like:

1
2
3
4
5
[Test]
public void MathTest()
{
    Assert.AreEqual(0, 1 + 1);
}

Running the tests again, the result would look like this:

Additional details come up — highlighting the failed test reveals the expectations of the failing test, the actual result, and even the stack trace, crucial for figuring out why the test is failing.

You’re now ready to use NUnit to code test-first for your classes.

But you could also use it for your front-end code, particularly web applications. On the next installment of this 2-part series I’ll show you how to use Selenium for front-end testing in Visual Studio.

References

Peter Provosts’s presentation on Visual Studio 2012 unit testing features in TechEd Europe was a crucial reference for this post.

Agile Software development

13 Oct

I heard much about Agile keywords but really do not have time to investigate what is it. Today I got some information and really enjoy this keyword. Actually, we have so many things to learn and investigate ^^.

As wikipedia.com, Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle. (Source http://en.wikipedia.org/wiki/Agile_software_development)

For more detail resource about this keyword, you can read this ebook.

INTRODUCTION Unknowable and Incommunicable 13
The Problem with Parsing Experience 14
The Impossibility of Communication 17
Three Levels of Listening 22
Chapter 1 A Cooperative Game of Invention and Communication 28
Software and Poetry 29
Software and Games 30
A Second Look at the Cooperative Game 35
Chapter 2 Individuals 43
Them’s Funky People 44
Overcoming Failure Modes 47
Working Better in Some Ways than Others 52
Drawing on Success Modes 61
Chapter 3 Communicating, Cooperating Teams 69
Convection Currents of Information 70
Jumping Communication Gaps 81
Teams as Communities 88
Teams as Ecosystems 95
What should I do tomorrow? 97
Chapter 4 Methodologies 100
An Ecosystem That Ships Software 101
Methodology Concepts 101
Methodology Design Principles 120
XP Under Glass 139
Why Methodology at All? 142
What Should I Do Tomorrow? 144
Chapter 5 Agile and Self-Adapting 146
Light But Sufficient 147
Agile 149
Becoming Self-Adapting 153
What Should I do Tomorrow? 161
Chapter 6 The Crystal Methodologies 164

Link download in here download

Selenium tutorial lesson by video

4 Jun

Please refer in here http://qtpselenium.com/selenium-tutorial/

It is so useful

Selenium Tutorial for Beginner/Tips for Experts

2 Jun

Selenium tutorial/overview

1. Selenium Introduction

2. Selenium Installation

3. Getting Started/Selenium RC steps

4. Selenium Tips and Quirks/FAQ

5. Extending Selenium

6. Selenium 2(pros/cons)

7. Load testing with selenium

8. Good Resources

9. Alternatives to Selenium

Source: http://www.jroller.com/selenium/category/Java

9 Important Tips for Selenium Remote Control (Java client) – Test Tool

2 Jun

By Angsuman Chakraborty, Gaea News Network
Wednesday, April 16, 2008

Selenium Remote Control (RC) is a test tool that allows you to write automated web application UI tests in many programming languages against any HTTP website using any mainstream JavaScript-enabled browser. Selenium RC is a powerful and simple framework for running (scheduled or manually) automated UI centric regression tests for web applications / services. Here are few simple tips for Selenium RC java client. I used JUnit for tests. You can use NGUnit too.

1. To run the Java client you need to only have selenium-java-client-driver.jar (located in selenium-remote-control-1.0-beta-1/selenium-java-client-driver-1.0-beta-1 ) in your classpath.

2. The automatically generated java file (from Selenium Core) is likely to be defective. Ensure at least you have the following import statements:

import com.thoughtworks.selenium.*;
import junit.framework.*;
import java.util.regex.Pattern;

3. Ensure that the saved file name matches the generated class file name.

4. Remove the package statement or replace it with your own package statement. Initially just remove it.

5. Error: java.lang.UnsupportedOperationException: Catch body broken: IOException from cmd=setContext&1=SeleniumSTSanityTest.testSimpleThoughts -> java.net.ConnectException: Connection refused

Have you run the Selenium server?
Run the Selenium server like this:
java -jar selenium-server.jar

The selenium server is located in:
selenium-remote-control-1.0-beta-1/selenium-server-1.0-beta-1

6. Error: com.thoughtworks.selenium.SeleniumException: ERROR Server Exception: sessionId should not be null; has this session been started yet?

Ensure that the browser is in the PATH before running the server. On my linux box I did:
export PATH=$PATH:/usr/lib/firefox-2.0.0.6/

7. Error: com.thoughtworks.selenium.SeleniumException: Permission denied to get property Location.href

This happens on Firefox when a previous page wasn’t fully loaded before the next page was invoked (due to timeout or click() was used). The solution is to use *chrome instead of *firefox in setup. I use for firefox:
setUp(”http://blog.taragana.com/”, “*chrome”);

8. Timeout error
Increase the time in selenium.waitForPageToLoad() to 60000 (1 minute) or more.

9. How to run the generated java Test file?
This is really a JUnit question but in short you can add the following code in the generated file to get it running:
public static Test suite() {
return new TestSuite(SeleniumSTSanityTest.class);
}

public static void main(String args[]) {
junit.textui.TestRunner.run(suite());
}

Note: Replace SeleniumSTSanityTest with the name of your Java source file (without the .java extension)

Source: http://tech.gaeatimes.com/index.php/archive/9-important-tips-for-selenium-remote-control-java-client-test-tool/

[Test tool] [Selenium] Learn how to use Selenium with Maven/Ant to automate testing of web apps

29 May

San Francisco Java User Group presents Chris Bedford who talks about:
– How to write functional tests with Selenium (including explaining its IDE, architecture, RC, and alternatives like Canoo WebTest)
– How to set up Selenium testing for web apps in continuous integration using Maven, Ant, Cargo, etc.
– How to use Hudson for build server (brief overview)

January 12, 2010 in San Francisco, CA
http://www.sfjava.org/calendar/11982857/