xUnit is a label used for an
automated testing software framework
In computer programming, a software framework is a software abstraction that provides generic functionality which developers can extend with custom code to create applications. It establishes a standard foundation for building and deploying soft ...
that shares significant structure and functionality that is traceable to a common progenitor
SUnit.
The SUnit framework was
ported to
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
by
Kent Beck
Kent Beck (born 1961) is an American software engineer and the creator of extreme programming, a software development methodology that eschews rigid formal specification for a collaborative and iterative design process. Beck was one of the 17 o ...
and
Erich Gamma as
JUnit
JUnit is a test automation framework for the Java programming language. JUnit is often used for unit testing, and is one of the xUnit frameworks.
JUnit is linked as a JAR at compile-time. The latest version of the framework, JUnit 5, resides ...
which gained wide popularity. Adaptations to other languages were also popular which led some to claim that the structured,
object-oriented
Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impleme ...
style works well with popular languages including Java and
C#.
The name of an adaptation is often a variation of "SUnit" with the "S" replaced with an abbreviation of the target language name. For example, JUnit for Java and RUnit for
R. The term "xUnit" refers to any such adaptation where "x" is a placeholder for the language-specific prefix.
The xUnit frameworks are often used for
unit testing
Unit testing, component or module testing, is a form of software testing by which isolated source code is tested to validate expected behavior.
Unit testing describes tests that are run at the unit-level to contrast testing at the Integration ...
testing an isolated unit of code but can be used for any level of
software testing
Software testing is the act of checking whether software satisfies expectations.
Software testing can provide objective, independent information about the Quality (business), quality of software and the risk of its failure to a User (computin ...
including
integration and
system
A system is a group of interacting or interrelated elements that act according to a set of rules to form a unified whole. A system, surrounded and influenced by its open system (systems theory), environment, is described by its boundaries, str ...
.
Architecture
An xUnit framework has the following general
architecture
Architecture is the art and technique of designing and building, as distinguished from the skills associated with construction. It is both the process and the product of sketching, conceiving, planning, designing, and construction, constructi ...
.
Test case
A
test case
In software engineering, a test case is a specification of the inputs, execution conditions, testing procedure, and expected results that define a single test to be executed to achieve a particular software testing objective, such as to exercise ...
is the smallest part of a test that generally encodes a simple path through the software under test. The test case code prepares input data and environmental state, invokes the software under test and verifies expected results.
A programmer writes the code for each test case.
Assertions
A test case is implemented with one or more
assertions that validate expected results.
Generally, the framework provides assertion functionality. A framework may provide a way to use custom assertions.
Test suite
A
test suite
In software development, a test suite, less commonly known as a validation suite, is a collection of test cases that are intended to be used to test a software program to show that it has some specified set of behaviors. A test suite often conta ...
is a collection of related test cases. They share a framework which allows for reuse of environment setup and cleanup code.
Generally, a test runner may run the cases of a suite in any order so the programmer should not depend on top-to-bottom execution order.
Test fixture
A
test fixture
A test fixture is a device used to consistently test some item, device, or piece of software. Test fixtures are used in the testing of electronics, software and physical devices.
Electronics
In testing electronic equipment such as circuit boa ...
(also known as a test context) provides the environment for each test case of a suite. Generally, a fixture is configured to setup a known, good,
runtime environment before tests run, and to cleanup the environment after.
The fixture is configured with one or more functions that setup and cleanup state. The test runner runs each setup function before each case and runs each cleanup function after.
Test runner
A test runner is a program that runs tests and reports results.
[Meszaros, Gerard (2007) ''xUnit Test Patterns'', Pearson Education, Inc./Addison Wesley] The program is often part of a framework.
A test runner may produce results in various formats. Often, a common and default format is
human-readable
In computing, a human-readable medium or human-readable format is any encoding of data or information that can be naturally read by humans, resulting in human-readable data. It is often encoded as ASCII or Unicode text, rather than as binary da ...
,
plain-text
In computing, plain text is a loose term for data (e.g. file contents) that represent only characters of readable material but not its graphical representation nor other objects (floating-point numbers, images, etc.). It may also include a limi ...
. Additionally, the runner may produce structured output. Some xUnit adaptations (i.e. JUnit) can output
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
that can be used by a continuous integration system such as
Jenkins and
Atlassian Bamboo.
See also
*
*
*
*
*
*
References
External links
*
*
*
* {{cite web , url= https://github.com/Umplify/xunit-dependency-injection , title= Open Source Dependency Injection for xUnit , website=
GitHub
GitHub () is a Proprietary software, proprietary developer platform that allows developers to create, store, manage, and share their code. It uses Git to provide distributed version control and GitHub itself provides access control, bug trackin ...
, series= Testing
Unit testing frameworks