<

Unit Test Frameworks

The first stage of ensuring a quality software product is to ensure that the development process makes use of automated, repeatable unit tests. SpiraTeam can integrate with all the major xUnit unit test frameworks to ensure that all features are being adequately covered.


.NET - NUnit


NUnit is a unit test framework for the Microsoft .NET platform that is based on the popular xUnit paradigm. Using NUnit allows you to develop automated unit test fixtures that can be used to either regression test an existing application or to define the intended functionality prior to development (using the Agile recommended test-driven development (TDD) approach).

When you use the SpiraTeam Add-In for NUnit it enables you to run automated NUnit tests against a .NET application and have the results be recorded as test runs inside SpiraTeam. This allows you to track your automated unit tests against the different releases in SpiraTeam and to have complete visibility of the overall requirements test coverage.

Note: This integration requires at least version 2.2 of SpiraTeam and version 2.5.5 of NUnit.

Integrating the Add-In With Your Tests

The NUnit add-in works by looking for additional test attributes that map the NUnit test fixtures to SpiraTeam test cases:

/// <summary>

/// Sample test that asserts a failure

/// </summary>

[

Test,

SpiraTestCase (<test case id>)

]

public void _01_SampleFailure()

{

//Failure Assertion

Assert.AreEqual (1, 0);

}

Then when the test is executed by NUnit, the Add-In will capture the results from the unit tests and report them back as automated test executions in SpiraTeam.


.NET - Visual Studio Unit Testing


Microsoft Visual Studio Team System (MS VSTS) Test (also known as MS-Test) is a unit test framework for the Microsoft .NET platform that comes built-in to Visual Studio Professional Edition. Using MS-Test allows you to develop automated unit test fixtures that can be used to either regression test an existing application or to define the intended functionality prior to development (using the Agile recommended test-driven development (TDD) approach).

When you use the SpiraTeam Extension for MS-Test it enables you to run automated unit tests against a .NET application and have the results be recorded as test runs inside SpiraTeam. This allows you to track your automated unit tests against the different releases in SpiraTeam and to have complete visibility of the overall requirements test coverage.

Note: This integration requires at least version 2.3 of SpiraTeam and Visual Studio 2008 Professional Edition.

Integrating the Extension With Your Tests

The MS-Test extension works by looking for additional test attributes that map the unit test fixtures to SpiraTeam test cases:

/// <summary>

/// Sample test that asserts a failure and overrides the default configuration

/// </summary>

[

TestMethod,

SpiraTestCase(5),

SpiraTestConfiguration("http://localhost/SpiraTest", "fredbloggs", "fredbloggs", 1, 1, 2)

]

public void SampleFail()

{

//Verify the state

Assert.AreEqual(2, testFixtureState, "*Real Error*: State not persisted");

//Failure Assertion

Assert.AreEqual(1, 0, "Failed as Expected");

}

Then when the test is executed by MS-Test, the extension will capture the results from the unit tests and report them back as automated test executions in SpiraTeam.


Java – Junit


JUnit is a unit test framework for the Java platform that is based on the popular xUnit paradigm. Using JUnit allows you to develop automated unit test fixtures that can be used to either regression test an existing application or to define the intended functionality prior to development (using the Agile recommended test-driven development (TDD) approach).

When you use the SpiraTeam Extension for JUnit it enables you to run automated JUnit tests against a Java application and have the results be recorded as test runs inside SpiraTeam. This allows you to track your automated unit tests against the different releases in SpiraTeam and to have complete visibility of the overall requirements test coverage.

Note: This integration requires at least version 3.0 of SpiraTeam and version 4.0 of JUnit.

Integrating the Extension With Your Tests

The JUnit extension works by looking for additional test annotations that map the JUnit test fixtures to SpiraTeam test cases:

/**

* Tests the addition of the two values

*/

@Test

@SpiraTestCase(testCaseId=5)

public void testAdd()

{

double result = fValue1 + fValue2;

// forced failure result == 5

assertTrue (result == 6);

}

Then when the test is executed by JUnit, the extension will capture the results from the unit tests and report them back as automated test executions in SpiraTeam.


Java – TestNG


TestNG is a unit test framework for the Java platform that is based on the popular xUnit paradigm. Using TestNG allows you to develop automated unit test fixtures that can be used to either regression test an existing application or to define the intended functionality prior to development (using the Agile recommended test-driven development (TDD) approach).

When you use the SpiraTeam Listener for TestNG it enables you to run automated TestNG tests against a Java application and have the results be recorded as test runs inside SpiraTeam. This allows you to track your automated unit tests against the different releases in SpiraTeam and to have complete visibility of the overall requirements test coverage.

Note: This integration requires at least version 3.0 of SpiraTeam and version 1.0 of TestNG running under JDK 1.5 or later.

Integrating the Listener With Your Tests

The TestNG listener works by looking for additional test annotations that map the TestNG test fixtures to SpiraTeam test cases:

/**

* Tests the addition of the two values

*/

@Test

@SpiraTestCase(testCaseId=5)

public void testAdd()

{

double result = fValue1 + fValue2;

// forced failure result == 5

assertTrue (result == 6);

}

Then when the test is executed by TestNG, the listener will capture the results from the unit tests and report them back as automated test executions in SpiraTeam.


Python – PyUnit


PyUnit is a unit test framework for the Python scripting language that is based on the popular xUnit paradigm. Using PyUnit allows you to develop automated unit test fixtures that can be used to either regression test an existing application or to define the intended functionality prior to development (using the Agile recommended test-driven development (TDD) approach).

When you use the SpiraTeam Extension for PyUnit it enables you to run automated PyUnit tests against a Python application and have the results be recorded as test runs inside SpiraTeam. This allows you to track your automated unit tests against the different releases in SpiraTeam and to have complete visibility of the overall requirements test coverage.

Note: This integration requires at least version 2.3 of SpiraTeam.

Integrating the Extension With Your Tests

The PyUnit extension works by looking for a special numeric suffix on each of the test methods that map the PyUnit test fixtures to SpiraTeam test cases:

def testchoice__3(self):

element = random.choice(self.seq)

self.assert_(element in self.seq)

releaseId = 1

testSetId = 1

spiraTestExtension = spiratestextension.SpiraTestExtension()

spiraTestExtension.projectId = 1

spiraTestExtension.server = "localhost"

spiraTestExtension.port = 80

spiraTestExtension.path = "SpiraTest"

spiraTestExtension.userName = "fredbloggs"

spiraTestExtension.password = "fredbloggs"

spiraTestExtension.recordResults(TestSequenceFunctions, testResult, releaseId, testSetId)

Then when the test is executed by PyUnit, the extension will capture the results from the unit tests and report them back as automated test executions in SpiraTeam.


Ruby – Test::Unit


Test::Unit is a unit test framework for the Ruby scripting language that is based on the popular xUnit paradigm. Using Test::Unit allows you to develop automated unit test fixtures that can be used to either regression test an existing application or to define the intended functionality prior to development (using the Agile recommended test-driven development (TDD) approach).

When you use the SpiraTeam custom runner for Test::Unit it enables you to run automated Test::Unit tests against a Ruby application and have the results be recorded as test runs inside SpiraTeam. This allows you to track your automated unit tests against the different releases in SpiraTeam and to have complete visibility of the overall requirements test coverage.

Note: This integration requires at least version 2.3 of SpiraTeam.

Integrating the Custom Runner With Your Tests

The Test::Unit custom runner works by looking for a special numeric suffix on each of the test methods that map the Test::Unit test fixtures to SpiraTeam test cases:

#this is a test case that tests addition operations

class TC_Adder < Test::Unit::TestCase

def setup

@adder = Adder.new(5)

end

def test_add__2

assert_equal(7, @adder.add(2), "Should have added correctly")

end

def test_addfail__3

assert_equal(7, @adder.add(3), "Test failure")

end

def teardown

@adder = nil

end

end

#this is a test suite that calls the test case

class TS_Examples

def self.suite

suite = Test::Unit::TestSuite.new

suite << TC_Adder.suite

return suite

end

end

projectId = 1

releaseId = 2

testSetId = -1

testRunner = Test::Unit::SpiraTest::TestRunner.new(TS_Examples, "http://servername/SpiraTest", "fredbloggs", "fredbloggs", projectId, releaseId, testSetId)

testRunner.start

Then when the test is executed by Test::Unit, the custom runner will capture the results from the unit tests and report them back as automated test executions in SpiraTeam.


Perl – Test Anything Protocol (TAP)


Perl’s Test Anything Protocol (TAP) is a unit test framework built into the Perl scripting language. Using TAP allows you to develop automated unit test harnesses that can be used to either regression test an existing application or to define the intended functionality prior to development (using the Agile recommended test-driven development (TDD) approach).

When you use the SpiraTeam Extensions for TAP it enables you to run automated TAP test harnesses against a Perl application and have the results be recorded as test runs inside SpiraTeam. This allows you to track your automated unit tests against the different releases in SpiraTeam and to have complete visibility of the overall requirements test coverage.

Note: This integration requires at least version 2.3 of SpiraTeam.

Integrating the Extensions With Your Test Harnesses

To use SpiraTeam with TAP, each of the TAP test case files needs to have a corresponding test case in SpiraTeam. These can be either existing test cases that have manual test steps or they can be new test cases designed specifically for automated testing and therefore have no defined test steps. In either case, no changes need to be made to the individual test cases:

#this is a test case that tests addition operations

#!/usr/bin/perl -w

use Inflectra::SpiraTest::Addons::SpiraHarness::Harness;

#instantiate the harness

my $harness = Inflectra::SpiraTest::Addons::SpiraHarness::Harness->new;

#specify the SpiraTeam custom harness properties

$spira_args = {};

$spira_args->{"base_url"} = "http://localhost/SpiraTest";

$spira_args->{"user_name"} = "fredbloggs";

$spira_args->{"password"} = "fredbloggs";

$spira_args->{"project_id"} = 1;

$spira_args->{"release_id"} = 1;

$spira_args->{"test_set_id"} = 1;

$harness->{"spira_args"} = $spira_args;

#define the list of tests and their SpiraTeam Mapping

#Hash is of the format: TestFile => Test Case ID

my $tests = {};

$tests->{"SampleTest1.pl"} = 2;

$tests->{"SampleTest2.pl"} = 3;

$harness->runtests($tests);

Firstly you need to use the SpiraTeam specific harness rather than the general TAP::Harness library. This new class is actually a subclass of the standard one, so it supports all the same methods, with the exception of the runtests command, which now accepts a Perl hashref rather than a simple array. This hashref includes the mapping between the Perl test harnesses and the corresponding SpiraTeam test cases.

Then when the test is executed by TAP, the extension will capture the results from the unit tests and report them back as automated test executions in SpiraTeam.


PHP – PHPUnit


PHPUnit is a unit test framework for the PHP scripting language that is based on the popular xUnit paradigm. Using PHPUnit allows you to develop automated unit test fixtures that can be used to either regression test an existing application or to define the intended functionality prior to development (using the Agile recommended test-driven development (TDD) approach).

When you use the SpiraTeam Extension for PHPUnit it enables you to run automated PHPUnit tests against a PHP application and have the results be recorded as test runs inside SpiraTeam. This allows you to track your automated unit tests against the different releases in SpiraTeam and to have complete visibility of the overall requirements test coverage.

Note: This integration requires at least version 2.3 of SpiraTeam.

Integrating the Extension With Your Tests

The PHPUnit extension works by looking for a special numeric suffix on each of the test methods that map the PHPUnit test fixtures to SpiraTeam test cases:

/**

* Tests the addition of the two values

*/

public function testAdd__2()

{

$result = $this->fValue1 + $this->fValue2;

// forced failure result == 5

$this->assertTrue ($result == 6);

}

// Create a test suite that contains the tests

// from the ArrayTest class

$suite = new PHPUnit_Framework_TestSuite('SimpleTest');

//Set the timezone identifier to match that used by the SpiraTeam server

date_default_timezone_set ("US/Eastern");

//Create a new SpiraTeam listener instance and specify the connection info

$spiraListener = new SpiraListener_Listener;

$spiraListener->setBaseUrl ('http://localhost/SpiraTeam');

$spiraListener->setUserName ('fredbloggs');

$spiraListener->setPassword ('fredbloggs');

$spiraListener->setProjectId (1);

$spiraListener->setReleaseId (1);

$spiraListener->setTestSetId (1);

// Create a test result and attach the SpiraTeam listener

// object as an observer to it (as well as the default console text listener)

$result = new PHPUnit_Framework_TestResult;

$textPrinter = new PHPUnit_TextUI_ResultPrinter;

$result->addListener($textPrinter);

$result->addListener($spiraListener);

// Run the tests and print the results

$result = $suite->run($result);

$textPrinter->printResult($result);

Then when the test is executed by PHPUnit, the extension will capture the results from the unit tests and report them back as automated test executions in SpiraTeam.


Selenium


Selenium is a test tool that allows you to write automated web application user interface tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser. Selenium comes in two parts.

  • A server which can automatically launch and kill supported browsers, and acts as a HTTP proxy for web requests from those browsers. There are two versions of Selenium available, Selenium-RC (Remote Control) and Selenium WebDriver.
  • Client libraries for various computer languages - these are referred to as ‘client drivers’.

Therefore to use SpiraTeam with Selenium-RC or Selenium WebDriver, you need to decide which client driver you want to use, and then use the appropriate integration between SpiraTeam and that driver’s underlying platform/language and unit test framework (e.g. JUnit, NUnit, PHPUnit, etc.). Once you have chosen the language, you can refer to the previous section of this page that describes how SpiraTeam integrates with that unit test framework.

About Inflectra

Our mission to helping our customers - large corporations, small businesses, professional services firms, government agencies and individual developers – with the means to effectively and affordably manage their software development and testing lifecycles, so as to decrease the time to market and increase return on investment.

At Inflectra, we are fully committed to provide our customers with the very best products and customer service. We believe in going the extra mile to ensure that each customer is satisfied with our software products. We have the experience and the commitment to deliver the products customers need to deliver their projects and assure quality every step of the way. (Learn More)

Our Guarantee

We are so confident that you will be fully satisfied with our products that we offer a 30-day, unconditional, money back guarantee! (Learn More)