Unit Tests gelten als das Mittel der Wahl wenn es darum geht die Erstellung qualitativ hochwertiger Software zu unterstützten. Je wichtiger diese Tests jedoch sind, desto wichtiger ist auch die Betrachtung was sich eigentlich dahinter verbirgt. Was genau ist eine Unit, wie beeinflusst unsere Definition des Begriffs das erzielte Ergebnis und wo ordnen sich diese Tests ein wenn es um bestimmte Vorgehen wie TDD oder BDD geht?
FEHLENDE DATEN? (K)EIN PROBLEM!: Die Kunst der Data Imputation
Was ist eigentlich eine Unit?
1.
2.
3. In der ersten Teststufe, dem Komponententest, werden die in der nach dem
V-Modell unmittelbar vorangehenden Programmierphase erstellten
Softwarebausteine erstmalig einem systematischen Test unterzogen.
Abhängig davon, welche Programmiersprache die Entwickler einsetzen,
werden diese kleinsten Softwareeinheiten unterschiedlich bezeichnet, zum
Beispiel als Module, Units oder Klassen (im Fall objektorientierter
Programmierung). Die entsprechenden Tests werden Modultest, Unit Test
bzw. Klassentest genannt.
Von der verwendeten Programmiersprache abstrahiert, wird von
Komponente oder Softwarebaustein gesprochen. Der Test eines solchen
einzelnen Softwarebausteins wird als Komponententest bezeichnet.
4. Unit Test
A unit test verifies the behavior of a small part of the overall system. It
may be as small as a single object or method that is a consequence of one
or more design decisions.
Component test
A component test verifies a component's behavior. Component tests help
with component design by testing interactions between objects.
A component is a larger part of the overall system that may be separately
deployable. For example, on the Windows platform, dynamic linked
libraries (DLLs) are used as components, Java Archives (JAR files) are
components on the Java platform, and a service-oliented architecture
(SOA) uses Web Services as components.
5. Unit Test
A unit test is an automated Piece of code that invokes the method or class
being tested and then checks some assumptions about the logical behavior
of that method or class. A unit test is almost always writen using a unit-
testing framework. It can be written easily and runs quickly. It‘s fully
automated, trustworthy, readable and maintainable.
Integration Test
Integration testing means testing two or more dependent sofware
modules as a group.
27. Unit tests run fast. If they don't run fast, they aren't unit tests. Other kinds
of tests offen masquerade as unit tests. A test is not a unit test if:
1. It talks to a database.
2. It communicates across a network.
3. It touches the file system.
4. You have to do special things to your environment (such as editing
configuration files) to run it.
Tests that do these things aren't bad. Often they are worth writing, and you
generally will write them in unit test harnesses. However, it is important to
be able to separate them from true unit tests so that you can keep a set of
tests that you can runfast whenever you make changes.
34. hohe Ergebnisgenauigkeit
Geringe Geschwindigkeit
je Test
Hohe Testanzahl
Geringer (Anfangs)aufwand
Hohe Ausführungsgeschwindigkeit
je Test
Geringe Testanzahl
Hoher (Anfangs)aufwand
Geringe Ergebnisgenauigkeit
47. public class When_no_data_is_entered_for_person
{
static Person sut;
Establish context = () => sut = new Person();
Because of = () => { /* nothing todo because we simply don't set any data */ };
It should_provide_an_error_text_for_BirthDate = () => sut["BirthDate"].ShouldNotBeEmpty();
It should_provide_an_error_text_for_FirstName = () => sut["FirstName"].ShouldNotBeEmpty();
It should_provide_an_error_text_for_LastName = () => sut["LastName"].ShouldNotBeEmpty();
}