Unit testing (eng)
Embed Size (px)
● What is Unit Testing? ● Benefits ● What is Test Driven Development? ● What is Behavior Driven Development? ● Categories of (Unit) Tests / Software Testing Pyramid, Frameworks ● C++, Java, .NET, Perl, PHP frameworks ● Unit-testing Zend Framework application
Transcript of Unit testing (eng)
- Unit Testing08/11/2011
- Softjourn Inc.Unit Testing Anatoliy Okhotnikov Softjourn Inc.
- Agenda What is Unit Testing? Benefits What is Test Driven Development? What is Behavior Driven Development? Categories of (Unit) Tests / Software Testing Pyramid, Frameworks C++, Java, .NET, Perl, PHP frameworks Unit-testing Zend Framework application
- What is Unit Testing? Ford new engine test area Special test harness that connects a gas and oil line For the output, a measuring device is connected to the drive shaft that comes directly out of the engine Engine starts and revs up Within about 5 minutes the computer is able to analyze the torque curve, gas usage, and oil usage
- What is Unit Testing? In computer programming, unit testing is a method by which individual units of source code are tested to determine if they are fit for use. A unit is the smallest testable part of an application. In procedural programming a unit may be an individual function or procedure. Unit tests are created by programmers or occasionally by white box testers. Ideally, each test case is independent from the others: substitutes like method stubs, mock objects, fakes and test harnesses can be used to assist testing a module in isolation. Unit tests are typically written and run by software developers to ensure that code meets its design and behaves as intended. Its implementation can vary from being very manual (pencil and paper) to being formalized as part of build automation
- Benefits The goal of unit testing is to isolate each part of the program and show that the individual parts are correct. A unit test provides a strict, written contract that the piece of code must satisfy. As a result, it affords several benefits. Find problems early (in the development cycle) Facilitates change (refactor, regression, etc.) Simplifies integration (parts, sum & integration) Documentation (live, understand API) Design (TDD, no formal design, design element)
- What is Test Driven Development? a software development process that relies on the repetition of a very short development cycle: first the developer writes a failing automated test case Test that defines a desired improvement or new function, then produces code to pass that test and finally refactors the Code new code to acceptable standards. Kent Beck, who is credited with Refactor having developed or rediscovered the technique, stated in 2003 that TDD encourages simple designs and inspires confidence.
- What is Behavior Driven Development? An agile software development technique that encourages collaboration between developers, QA and non-technical or business participants in a software project. A response to Test Driven Development, including Acceptance Test or Customer Test Driven Development practices as found in Extreme Programming. It extends TDD by writing test cases in a natural language that non-programmers can read. With a Feature Injection, BDD covers the analysis space and provides a full treatment of the software lifecycle from vision through to code and release.
- Test Categories
- Categories of (Unit) Tests Small: Unit Tests Check conditional logic in the code A debugger should not be required in case of failure Medium: Functional Tests Check whether the interfaces between classes abide by their contracts Large: End-to-End Tests Check for wiring bugs
- Software Testing Pyramid
- C++ CppUnit Differences in compilers, platforms, and programming Boost.Test styles. C++ is not exactly a CppUnitLite clean, fully supported NanoCppUnit language, with one coding standard. Unit++ List of features you want CxxTest Timing support: individual/total Unit Test++ Installation, Creation, Modification, etc.
- UnitTest++ http://unittest-cpp.sourceforge.net/UnitTest++.html Lightweight unit testing framework for C++ Designed to do test-driven development on a wide variety of platforms Simplicity, portability, speed, and small footprint ANSI portable C++: Win32, Linux, Mac OS X Written and maintained by Charles Nicholson and Noel Llopis C++ For Game Programmers
- UnitTest++ Example a minimal C++ program to run a failing test through UnitTest++ UnitTest++$ g++ -I./src -c test.cpp -o test.o UnitTest++$ g++ test.o libUnitTest++.a -o test UnitTest++$ ./test test.cpp:6: error: Failure in FailSpectacularly: false FAILURE: 1 out of 1 tests failed (1 failures). Test time: 0.00 seconds.
- Java JUnit Java has an abundance of libraries that can help with the TestNG development of your tests cases JTest Unit tests are fairly easy to write Cactus and have very rapid performance, Mockito so its not going to take you long to run them. JWalk Dont Sacrifice Design for the SureAssert Sake of Testing Use Statistical Testing for Non- deterministic Code
- JUnit http://junit.sourceforge.net/ JUnit is a simple framework to code repeatable tests written by Erich Gamma and Kent Beck. It is used by the developer who implements unit tests in Java. Most famous of XUnits, JUnit is Open Source Software. Annotate a method with @org.junit.Test When you want to check a value, import static org.junit.Assert.*, call assertTrue() and pass a boolean that is true if the test succeeds
- JUnit Example a minimal Java class to run a successful test junit$ javac -cp junit-4.10.jar MyFirstTest.java junit$ java -cp junit-4.10.jar:. org.junit.runner.JUnitCore MyFirstTest JUnit version 4.10 Time: 0.004 OK (1 test)
- .NET csUnit There are a wide variety of unit testing tools available for .NET. MSTest Fortunately, the structure of unit NUnit tests is similar within most of the NUnitAsp frameworks. .TEST NUnit has historically been one of the most popular frameworks xUnit.net There are 2 main parts of a unit Visual testing system, the testing Studio framework and a test runner.
- NUnit http://www.nunit.org/ initially ported from JUnit 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 has two different ways to run your tests. The console runner, nunit-console.exe, is the fastest to launch, but is not interactive. The gui runner, nunit.exe, is a Windows Forms application that allows you to work selectively with your tests and provides graphical feedback
- NUnit Example [TestFixture] is the way to indicate that the class contains test code. [Test] is an indication that it is a test method. TransferFunds : expected but was
- Perl Test::More Put your tests in t/ and follow the convention of ##-name.t. TAP Create a "Smoke Test" script and Test::Harness a bunch of generic tests Test::Unit Its as simple as deciding what Test::Class you want to write, writing a test Test::Builder for what you are going to write, then writing the code that does it Test::Able Start of by creating a file called tdd_is_cool.pm and a file called tdd_is_cool.t
- Test::More http://search.cpan.org/perldoc?Test::More Yet another framework for writing test scripts By convention, each test is assigned a number in order, often very useful to assign a name Before anything else, you need a testing plan use Test::More tests => 23; ... run y