SlideShare ist ein Scribd-Unternehmen logo
1 von 48
© OPITZ CONSULTING GmbH 2013 Seite 1Zum Beispiel ein Test
Zum Beispiel ein Test
Beispiele als Grundlage für
Anforderungsanalyse, Spezifikation und Implementierung
© OPITZ CONSULTING GmbH 2013 Seite 2Zum Beispiel ein Test
Zu meiner Person
Torsten Mandry
Solution Architect
OPITZ CONSULTING Deutschland GmbH
Entwurf und Entwicklung von
Enterprise Java Anwendungen
Anforderungsanalyse und
automatisiertes Testen
E-Mail: torsten.mandry@opitz-consulting.com
Twitter: @torstenmandry
Google: +torsten.mandry
© OPITZ CONSULTING GmbH 2013 Seite 3Zum Beispiel ein Test
Märkte
Java
SOA
ORACLE
BI/DWH
Outtasking
Kunden
Branchen-
übergreifend
Über 600
Kunden
Leistungs-
angebot
IT-Strategie
Beratung
Implementierung
Betrieb
Training
Fakten
Gründung 1990
400 Mitarbeiter
8 Standorte in
D/PL
Industrie / Versorger /
Telekommunikation
29%
Handel / Logistik /
Dienstleistungen
29%
42%
Öffentliche Auftraggeber /
Banken & Versicherungen /
Vereine & Verbände
© OPITZ CONSULTING GmbH 2011
© OPITZ CONSULTING GmbH 2013 Seite 4Zum Beispiel ein Test
Agenda
• Erfahrungen und
Erkenntnisse
• Verwendung von
Beispielen
• Vom Beispiel
zum Test
• Akzeptanztest
Frameworks
Foto: arquera@Flickr
© OPITZ CONSULTING GmbH 2013 Seite 5Zum Beispiel ein Test
Foto: Brady Withers@Flickr
Erfahrungen und Erkenntnisse
© OPITZ CONSULTING GmbH 2013 Seite 6Zum Beispiel ein Test
Entwicklung eines neuen Features
AnalystAuftraggeber Entwickler
Anforderung(en) Spezifikation Implementierung
© OPITZ CONSULTING GmbH 2013 Seite 7Zum Beispiel ein Test
Häufiges Ergebnis
Bild: dullhunk@Flickr
© OPITZ CONSULTING GmbH 2013 Seite 8Zum Beispiel ein Test
Spezifikation wird interpretiert
Auftraggeber Analyst Entwickler
© OPITZ CONSULTING GmbH 2013 Seite 9Zum Beispiel ein Test
Was läuft schief?
Wir spezifizieren
missverständlich
Wir verstehen „Problem“
des Kunden nicht
Wir kennen die Kriterien
des Kunden nicht
Wir haben kein
gemeinsames
Verständnis
Foto: Horia Varlan@Flickr
© OPITZ CONSULTING GmbH 2013 Seite 10Zum Beispiel ein Test
Beispiele
Foto: jonny goldstein@Flickr
© OPITZ CONSULTING GmbH 2013 Seite 11Zum Beispiel ein Test
Foto: bridgells@photobucket.com
?
?
?
Eine übliche Anforderung
Die Afa einer Investition ergibt sich aus dem
Investitionswert, linear verteilt über den
Abschreibungszeitraum, beginnend mit dem
Monat der Aktivierung!
© OPITZ CONSULTING GmbH 2013 Seite 12Zum Beispiel ein Test
Können Sie uns dazu ein Beispiel nennen?
Wenn wir eine Investition im Wert von 600 TEUR
getätigt haben, die am 01.01.2012 aktiviert wurde,
dann folgt daraus, bei einer Abschreibungsdauer
von 60 Monaten, eine monatliche AfA in Höhe von
10 TEUR und zwar von Jan/2012 bis Dez/2016.
© OPITZ CONSULTING GmbH 2013 Seite 13Zum Beispiel ein Test
Etwas anders formuliert…
dann folgt daraus
eine monatliche AfA
in Höhe von 10 TEUR
in der Zeit von Jan/2012 bis Dez/2016.
Wenn wir die Afa berechnen
Wir haben eine Investition
im Wert von 600 TEUR
aktiviert am 01.01.2012
und eine Abschreibungsdauer von 60 Monaten
Ausgangssituation / -zustand
Aktion / Ereignis
Erwartetes Ergebnis
© OPITZ CONSULTING GmbH 2013 Seite 14Zum Beispiel ein Test
Beispiele helfen…
 veranschaulichen / verdeutlichen
 decken Fragen / Lücken auf
 zwingen zum Nachdenken
 führen zu weiteren / detaillierteren Beispielen
 können nachgestellt werden
Foto: therichbrooks@Flickr
© OPITZ CONSULTING GmbH 2013 Seite 15Zum Beispiel ein Test
…können aber schwierig sein
 ungewohnt / erfordern Übung
 komplexe Zusammenhänge
 viele Einflussfaktoren / Vorbedingungen
 was ist relevant, was nicht?
 Auf das Wesentliche Konzentrieren
Foto: andrewrennie@Flickr
© OPITZ CONSULTING GmbH 2013 Seite 16Zum Beispiel ein Test
„Nachspezifikation“
„Das haben wir doch alles schon mal besprochen!“
„Alles wie bisher, nur...“
 Grundlegende
Beispiele als Basis
Foto: electricnerve@Flickr
© OPITZ CONSULTING GmbH 2013 Seite 17Zum Beispiel ein Test
Foto: anieto2k@Flickr
Spezifikation wird durch Beispiele
nicht einfacher…
…sondern besser!
© OPITZ CONSULTING GmbH 2013 Seite 18Zum Beispiel ein Test
Specification by Example
Beispiele als alleinige Spezifikation
 alle relevante Funktionalität
 vollständig mit Beispielen beschrieben
 keine „Prosa“-Spezifikation mehr notwendig
Foto: VickyvS@flickr.com
© OPITZ CONSULTING GmbH 2013 Seite 19Zum Beispiel ein Test
„sanfter“ Mittelweg
Beispiele als Ergänzung
zur Prosa-Spezifikation
 Prosa
 Problemstellung / Motivation
 Rahmenbedingungen
 Hintergründe
 Beispiele
 Verdeutlichung / Detaillierung
 Sonder- / Randfälle
 Konkretisierung
Foto: tinyfroglet@Flickr
© OPITZ CONSULTING GmbH 2013 Seite 20Zum Beispiel ein Test
Beispiele als „Definition of Done“
Wenn alle definierten Beispiele
erfolgreich durchlaufen werden
ist das Feature fertig
Foto: jayneandd@flickr.com
© OPITZ CONSULTING GmbH 2013 Seite 21Zum Beispiel ein Test
Vom Beispiel zum Test
© OPITZ CONSULTING GmbH 2013 Seite 22Zum Beispiel ein Test
public class InvestmentPosition extends Position {
…
public void calculateArmortisation() {
if (initiationDate == null)
throw new IllegalStateException("initiation date not set");
if (amount == null)
throw new IllegalStateException("amount not set");
if (project == null)
throw new IllegalStateException("project not set");
if (project.getStartDate() == null || project.getEndDate() == null)
throw new IllegalStateException("project start/end date not set");
armortisation.clear();
int armortisationMonths = ProjectManagementApp.getInstance().getArmortisationMonths();
BigDecimal monthlyAmount = amount.divide(BigDecimal.valueOf(armortisationMonths));
for (int i = 0; i < armortisationMonths; i++) {
Calendar monthYear = new GregorianCalendar();
monthYear.setTime(initiationDate);
monthYear.add(Calendar.MONTH, i);
int month = monthYear.get(Calendar.MONTH) + 1;
int year = monthYear.get(Calendar.YEAR);
armortisation.add(new PositionValue(this, month, year, monthlyAmount));
}
}
…
}
Code Beispiel
© OPITZ CONSULTING GmbH 2013 Seite 23Zum Beispiel ein Test
Unser Beispiel von eben
dann folgt daraus
eine monatliche AfA
in Höhe von 10 TEUR
in der Zeit von Jan/2012 bis Dez/2016.
Wenn wir die Afa berechnen
Wir haben eine Investition
im Wert von 600 TEUR
aktiviert am 01.01.2012
und eine Abschreibungsdauer von 60 Monaten
Ausgangssituation / -zustand
Aktion / Ereignis
Erwartetes Ergebnis
© OPITZ CONSULTING GmbH 2013 Seite 24Zum Beispiel ein Test
JUnit Test
@Test
public void calculateArmortisationTest() {
// Gegeben sei eine Investition
InvestmentPosition investment = new InvestmentPosition("any position name");
// im Wert von 600 TEUR
investment.setAmount(BigDecimal.valueOf(600000));
// aktiviert am 01.01.2012
investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
// und eine Abschreibungsdauer von 60 Monaten
ProjectManagementApp.getInstance().setArmortisationMonths(60);
// und noch einiges mehr...
Project project = new Project("any project name");
project.addPosition(investment);
project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime());
// wenn die Abschreibung berechnet wird
investment.calculateArmortisation();
// dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR
// in der Zeit von 01/2012 bis 12/2016
assertEquals("number of armortisation values", 60, investment.getArmortisation().size());
for (int i = 0; i < 60; i++) {
PositionValue value = investment.getArmortisation().get(i);
Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1);
expectedMonthYear.add(Calendar.MONTH, i);
assertEquals(format("value %d - month", i), expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth());
assertEquals(format("value %d - year", i), expectedMonthYear.get(Calendar.YEAR), value.getYear());
assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000), value.getAmount());
}
}
© OPITZ CONSULTING GmbH 2013 Seite 25Zum Beispiel ein Test
JUnit Test
@Test
public void calculateArmortisationTest() {
// Gegeben sei eine Investition
InvestmentPosition investment = new InvestmentPosition("any position name");
// im Wert von 600 TEUR
investment.setAmount(BigDecimal.valueOf(600000));
// aktiviert am 01.01.2012
investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
// und eine Abschreibungsdauer von 60 Monaten
ProjectManagementApp.getInstance().setArmortisationMonths(60);
// und noch einiges mehr...
Project project = new Project("any project name");
project.addPosition(investment);
project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime());
// wenn die Abschreibung berechnet wird
investment.calculateArmortisation();
// dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR
// in der Zeit von 01/2012 bis 12/2016
assertEquals("number of armortisation values", 60, investment.getArmortisation().size());
for (int i = 0; i < 60; i++) {
PositionValue value = investment.getArmortisation().get(i);
Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1);
expectedMonthYear.add(Calendar.MONTH, i);
assertEquals(format("value %d - month", i), expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth());
assertEquals(format("value %d - year", i), expectedMonthYear.get(Calendar.YEAR), value.getYear());
assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000), value.getAmount());
}
}
// Gegeben sei eine Investition
InvestmentPosition investment = new InvestmentPosition("any position name");
// im Wert von 600 TEUR
investment.setAmount(BigDecimal.valueOf(600000));
// aktiviert am 01.01.2012
investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
// und eine Abschreibungsdauer von 60 Monaten
ProjectManagementApp.getInstance().setArmortisationMonths(60);
© OPITZ CONSULTING GmbH 2013 Seite 26Zum Beispiel ein Test
JUnit Test
@Test
public void calculateArmortisationTest() {
// Gegeben sei eine Investition
InvestmentPosition investment = new InvestmentPosition("any position name");
// im Wert von 600 TEUR
investment.setAmount(BigDecimal.valueOf(600000));
// aktiviert am 01.01.2012
investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
// und eine Abschreibungsdauer von 60 Monaten
ProjectManagementApp.getInstance().setArmortisationMonths(60);
// und noch einiges mehr...
Project project = new Project("any project name");
project.addPosition(investment);
project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime());
// wenn die Abschreibung berechnet wird
investment.calculateArmortisation();
// dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR
// in der Zeit von 01/2012 bis 12/2016
assertEquals("number of armortisation values", 60, investment.getArmortisation().size());
for (int i = 0; i < 60; i++) {
PositionValue value = investment.getArmortisation().get(i);
Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1);
expectedMonthYear.add(Calendar.MONTH, i);
assertEquals(format("value %d - month", i), expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth());
assertEquals(format("value %d - year", i), expectedMonthYear.get(Calendar.YEAR), value.getYear());
assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000), value.getAmount());
}
}
// und noch einiges mehr...
Project project = new Project("any project name");
project.addPosition(investment);
project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime());
© OPITZ CONSULTING GmbH 2013 Seite 27Zum Beispiel ein Test
JUnit Test
@Test
public void calculateArmortisationTest() {
// Gegeben sei eine Investition
InvestmentPosition investment = new InvestmentPosition("any position name");
// im Wert von 600 TEUR
investment.setAmount(BigDecimal.valueOf(600000));
// aktiviert am 01.01.2012
investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
// und eine Abschreibungsdauer von 60 Monaten
ProjectManagementApp.getInstance().setArmortisationMonths(60);
// und noch einiges mehr...
Project project = new Project("any project name");
project.addPosition(investment);
project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime());
// wenn die Abschreibung berechnet wird
investment.calculateArmortisation();
// dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR
// in der Zeit von 01/2012 bis 12/2016
assertEquals("number of armortisation values", 60, investment.getArmortisation().size());
for (int i = 0; i < 60; i++) {
PositionValue value = investment.getArmortisation().get(i);
Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1);
expectedMonthYear.add(Calendar.MONTH, i);
assertEquals(format("value %d - month", i), expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth());
assertEquals(format("value %d - year", i), expectedMonthYear.get(Calendar.YEAR), value.getYear());
assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000), value.getAmount());
}
}
// wenn die Abschreibung berechnet wird
investment.calculateArmortisation();
© OPITZ CONSULTING GmbH 2013 Seite 28Zum Beispiel ein Test
JUnit Test
@Test
public void calculateArmortisationTest() {
// Gegeben sei eine Investition
InvestmentPosition investment = new InvestmentPosition("any position name");
// im Wert von 600 TEUR
investment.setAmount(BigDecimal.valueOf(600000));
// aktiviert am 01.01.2012
investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
// und eine Abschreibungsdauer von 60 Monaten
ProjectManagementApp.getInstance().setArmortisationMonths(60);
// und noch einiges mehr...
Project project = new Project("any project name");
project.addPosition(investment);
project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime());
project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime());
// wenn die Abschreibung berechnet wird
investment.calculateArmortisation();
// dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR
// in der Zeit von 01/2012 bis 12/2016
assertEquals("number of armortisation values", 60, investment.getArmortisation().size());
for (int i = 0; i < 60; i++) {
PositionValue value = investment.getArmortisation().get(i);
Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1);
expectedMonthYear.add(Calendar.MONTH, i);
assertEquals(format("value %d - month", i), expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth());
assertEquals(format("value %d - year", i), expectedMonthYear.get(Calendar.YEAR), value.getYear());
assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000), value.getAmount());
}
}
// dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR
// in der Zeit von 01/2012 bis 12/2016
assertEquals("number of armortisation values", 60,
investment.getArmortisation().size());
for (int i = 0; i < 60; i++) {
PositionValue value = investment.getArmortisation().get(i);
Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1);
expectedMonthYear.add(Calendar.MONTH, i);
assertEquals(format("value %d - month", i),
expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth());
assertEquals(format("value %d - year", i),
expectedMonthYear.get(Calendar.YEAR), value.getYear());
assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000),
value.getAmount());
}
© OPITZ CONSULTING GmbH 2013 Seite 29Zum Beispiel ein Test
Testdata Factory
erzeugt Domänen-Objekte
gefüllt mit Default-Daten
vollständig valide
Zwei nützliche Helfer
Configurable Entity
ermöglich konfigurieren
Fluent Interface
Foto: florianric@Flickr
© OPITZ CONSULTING GmbH 2013 Seite 30Zum Beispiel ein Test
Configurable Entity
public class ConfigurableInvestmentPosition extends InvestmentPosition {
public ConfigurableInvestmentPosition(String name) {
super(name);
}
public ConfigurableInvestmentPosition withAmount(double amount) {
this.setAmount(BigDecimal.valueOf(amount));
return this;
}
public ConfigurableInvestmentPosition withInitiationDate(Date initiationDate) {
this.setInitiationDate(initiationDate);
return this;
}
public ConfigurableInvestmentPosition withInitiationDate(int day,
int month, int year) {
this.setInitiationDate(DateBuilder.givenDate(day, month, year).toDate();
return this;
}
…
}
© OPITZ CONSULTING GmbH 2013 Seite 31Zum Beispiel ein Test
Testdata Factory
public class InvestmentPositionFactory {
private static final String DEFAULT_NAME = "any position name";
private static final double DEFAULT_AMOUNT = 100000;
private static final Date DEFAULT_INITIATION_DATE =
DateBuilder.givenDate(1, 1, 2012).toDate();
private static final String DEFAULT_COST_CENTER = "66666";
public static ConfigurableInvestmentPosition createDefault() {
ConfigurableInvestmentPosition investmentPosition =
new ConfigurableInvestmentPosition(DEFAULT_NAME)
.withAmount(DEFAULT_AMOUNT)
.withInitiationDate(DEFAULT_INITIATION_DATE)
.withCostCenter(DEFAULT_COST_CENTER);
Project project = ProjectFactory.createDefault();
project.addPosition(investmentPosition);
return investmentPosition;
}
}
© OPITZ CONSULTING GmbH 2013 Seite 32Zum Beispiel ein Test
Besserer JUnit Test
@Test
public void betterCalculateArmortisationTest() {
// Gegeben sei eine Investition
// im Wert von 600 TEUR
// aktiviert am 01.01.2012
InvestmentPosition investment = InvestmentPositionFactory.createDefault()
.withAmount(600000)
.withInitiationDate(1, 1, 2012);
// und eine Abschreibungsdauer von 60 Monaten
ProjectManagementApp.getInstance().setArmortisationMonths(60);
// wenn die Abschreibung berechnet wird
investment.calculateArmortisation();
// dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR
// in der Zeit von 01/2012 bis 12/2016
assertThat(investment.getArmortisation(), hasConstantAmount(10000));
assertThat(investment.getArmortisation(), containsMonthsFromTo( 1, 2012,
12, 2016));
}
Hamcrest
Matchers
© OPITZ CONSULTING GmbH 2013 Seite 33Zum Beispiel ein Test
Akzeptanztest Frameworks
http://jbehave.org/ http://cukes.info/
http://www.concordion.org/
© OPITZ CONSULTING GmbH 2013 Seite 34Zum Beispiel ein Test
Akzeptanztest Frameworks
http://jbehave.org/
© OPITZ CONSULTING GmbH 2013 Seite 35Zum Beispiel ein Test
User Story
calculate_armortisation_of_an_investment_position.story
Narrative:
As a user
I want to calculate the armortisation of an investment position
So that I can see the monthly armortisation amounts
Scenario: calculate armortisation for 600000 EUR and 60 months
Given an investment position with amount 600000 EUR initiated on 01.01.2012
And an armortisation time of 60 months
When I calculate the armortisation of the investment position
Then the monthly armortisation amount is 10000 EUR
And the armortisation runs from 01/2012 to 12/2016
Scenario: calculate armortisation for 30000 EUR and 24 months
Given an investment position with amount 30000 EUR initiated on 01.01.2012
And an armortisation time of 24 months
When I calculate the armortisation of the investment position
Then the monthly armortisation amount is 1250 EUR
And the armortisation runs from 01/2012 to 12/2013
© OPITZ CONSULTING GmbH 2013 Seite 36Zum Beispiel ein Test
Mapped Steps
public class CalculateArmortisationSteps {
private InvestmentPosition investment;
@Given("an investment position with amount $amount EUR initiated on $initiationDate")
public void setupInvestmentPosition(double amount, String initiationDate) {
investment = InvestmentPositionFactory.createDefault()
.withAmount(amount)
.withInitiationDate(initiationDate);
}
@Given("an armortisation time of $months months")
public void setupArmortisationPeriod(int months) {
ProjectManagementApp.getInstance().setArmortisationMonths(months);
}
@When("I calculate the armortisation of the investment position")
public void calculateArmortisation() {
investment.calculateArmortisation();
}
@Then("the monthly armortisation amount is $amount EUR")
public void assertMonthlyArmortisationAmount(double amount) {
assertThat(investment.getArmortisation(), hasConstantAmount(amount));
}
…
}
© OPITZ CONSULTING GmbH 2013 Seite 37Zum Beispiel ein Test
Testergebnis
© OPITZ CONSULTING GmbH 2013 Seite 38Zum Beispiel ein Test
Fehlerfall
© OPITZ CONSULTING GmbH 2013 Seite 39Zum Beispiel ein Test
Akzeptanztest Frameworks
http://www.concordion.org/
© OPITZ CONSULTING GmbH 2013 Seite 40Zum Beispiel ein Test
Spezifikation
<html xmlns:concordion="http://www.concordion.org/2007/concordion">
<body>
<h1>Calculate armortisation of an investment position</h1>
…
<div class="example">
<h3>Scenario: calculate armortisation for 600000 EUR and 60 months</h3>
<p concordion:execute="#investment = setupInvestmentPosition(#amount, #initiationDate)">
Given an investment position
with amount <strong concordion:set="#amount">600000</strong> EUR
initiated on <strong concordion:set="#initiationDate">01.01.2012</strong></p>
<p concordion:execute="setupArmortisationTime(#months)">
And an armortisation time of <strong concordion:set="#months">60</strong> months</p>
<p>When I <strong concordion:execute="calculateArmortisation(#investment)">calculate
the armortisation of the investment position</strong></p>
<p>Then the monthly armortisation amount is <strong concordion:assertEquals=
"monthlyArmortisationAmount(#investment)">10000,00</strong> EUR</p>
<p>And the armortisation runs
from <strong concordion:assertEquals="armortisationStart(#investment)">01/2012</strong>
to <strong concordion:assertEquals="armortisationEnd(#investment)">12/2016</strong>
…
© OPITZ CONSULTING GmbH 2013 Seite 41Zum Beispiel ein Test
Fixture
@RunWith(ConcordionRunner.class)
public class CalculateArmortisationOfAnInvestmentPositionFixture {
public InvestmentPosition setupInvestmentPosition(double amount,
String initiationDate) {
return InvestmentPositionFactory.createDefault()
.withAmount(amount)
.withInitiationDate(initiationDate);
}
public void setupArmortisationTime(int months) {
ProjectManagementApp.getInstance().setArmortisationMonths(months);
}
public void calculateArmortisation(InvestmentPosition investment) {
investment.calculateArmortisation();
}
…
© OPITZ CONSULTING GmbH 2013 Seite 42Zum Beispiel ein Test
Fixture
public String armortisationStart(InvestmentPosition investment) {
PositionValue firstValue = getSortedPositionValues(investment).get(0);
return format("%02d/%4d", firstValue.getMonth(), firstValue.getYear());
}
public String armortisationEnd(InvestmentPosition investment) {
List<PositionValue> values = getSortedPositionValues(investment);
PositionValue lastValue = values.get(values.size() - 1);
return format("%02d/%4d", lastValue.getMonth(), lastValue.getYear());
}
public boolean isContinousArmortisation(InvestmentPosition investment) {
return containsMonthsFromTo(armortisationStart(investment),
armortisationEnd(investment)).matches(investment.getArmortisation());
}
…
© OPITZ CONSULTING GmbH 2013 Seite 43Zum Beispiel ein Test
Testergebnis
© OPITZ CONSULTING GmbH 2013 Seite 44Zum Beispiel ein Test
Fehlerfall
© OPITZ CONSULTING GmbH 2013 Seite 45Zum Beispiel ein Test
Fehlerfall
© OPITZ CONSULTING GmbH 2013 Seite 46Zum Beispiel ein Test
Lebende Spezifikation
 Beschreibung der vollständigen Funktionalität
 in Form von automatisierten Akzeptanztests
© OPITZ CONSULTING GmbH 2013 Seite 47Zum Beispiel ein Test
Referenzen
 Code-Beispiele:
https://github.com/torstenmandry/testing-samples
 Torsten Mandry: “Configurable entities with fluent
interface”, http://javandry.blogspot.de/2012/11/configurable-entities-with-
fluent.html, 2012
 Gojko Adzic: „Bridging the Communication Gap –
Specification by Example and Agile Acceptance Testing”,
Neuri Limited, 2011
 JBehave: http://jbehave.org/
 Cucumber: http://cukes.info/
 Concordion: http://www.concordion.org/
© OPITZ CONSULTING GmbH 2013 Seite 48Zum Beispiel ein Test
Danke für Ihre Aufmerksamkeit

Weitere ähnliche Inhalte

Ähnlich wie Zum Beispiel ein Test

sitacon - Solutions in Tourism
sitacon - Solutions in Tourism sitacon - Solutions in Tourism
sitacon - Solutions in Tourism sitacon
 
Continuous Relaunch - Impulsvortrag auf der relaunch Konferenz 2014
Continuous Relaunch - Impulsvortrag auf der relaunch Konferenz 2014Continuous Relaunch - Impulsvortrag auf der relaunch Konferenz 2014
Continuous Relaunch - Impulsvortrag auf der relaunch Konferenz 2014kernpunkt
 
Hilfe, meine Organisation ist digital und agil!
Hilfe, meine Organisation ist digital und agil!Hilfe, meine Organisation ist digital und agil!
Hilfe, meine Organisation ist digital und agil!Ayelt Komus
 
Excel ade: Revolutionieren Sie Ihr ESG-Reporting
Excel ade: Revolutionieren Sie Ihr ESG-ReportingExcel ade: Revolutionieren Sie Ihr ESG-Reporting
Excel ade: Revolutionieren Sie Ihr ESG-ReportingIBsolution GmbH
 
Skalierte agile Methoden und Lean für das IT Demand- und Portfoliomanagment
Skalierte agile Methoden und Lean für das IT Demand- und PortfoliomanagmentSkalierte agile Methoden und Lean für das IT Demand- und Portfoliomanagment
Skalierte agile Methoden und Lean für das IT Demand- und PortfoliomanagmentAyelt Komus
 
Busines Cases __ tekom-Jahrestagung 2014
Busines Cases __ tekom-Jahrestagung 2014Busines Cases __ tekom-Jahrestagung 2014
Busines Cases __ tekom-Jahrestagung 2014Michael Schaffner
 
Tisson & Company IT Management - Architektur
Tisson & Company IT Management - ArchitekturTisson & Company IT Management - Architektur
Tisson & Company IT Management - ArchitekturHorst Tisson
 
Brennglas Corona
Brennglas CoronaBrennglas Corona
Brennglas CoronaAyelt Komus
 
Stars to road sbb svenkrause
Stars to road sbb svenkrauseStars to road sbb svenkrause
Stars to road sbb svenkrauseSven Krause
 
Beidhändiges Projektportfoliomanagement – Mit Stacey, Lean und Scaled Agile e...
Beidhändiges Projektportfoliomanagement – Mit Stacey, Lean und Scaled Agile e...Beidhändiges Projektportfoliomanagement – Mit Stacey, Lean und Scaled Agile e...
Beidhändiges Projektportfoliomanagement – Mit Stacey, Lean und Scaled Agile e...Ayelt Komus
 
Design Thinking - Arbeitsform für den Wandel
Design Thinking - Arbeitsform für den WandelDesign Thinking - Arbeitsform für den Wandel
Design Thinking - Arbeitsform für den Wandelgezeitenraum gbr
 
Juni 2015: The Lean Startup / Vorlesung "Entrepreneurship & Intrapreneurship"...
Juni 2015: The Lean Startup / Vorlesung "Entrepreneurship & Intrapreneurship"...Juni 2015: The Lean Startup / Vorlesung "Entrepreneurship & Intrapreneurship"...
Juni 2015: The Lean Startup / Vorlesung "Entrepreneurship & Intrapreneurship"...Dr. Judith Grummer
 
- Erfolgsfaktoren im Projektmanagement - Studienergebnisse und praktische Emp...
- Erfolgsfaktoren im Projektmanagement - Studienergebnisse und praktische Emp...- Erfolgsfaktoren im Projektmanagement - Studienergebnisse und praktische Emp...
- Erfolgsfaktoren im Projektmanagement - Studienergebnisse und praktische Emp...Ayelt Komus
 
The Lean Startup - Growth Hacking, Traction
The Lean Startup - Growth Hacking, TractionThe Lean Startup - Growth Hacking, Traction
The Lean Startup - Growth Hacking, TractionDr. Judith Grummer
 
Agile Coffeebreak Team agil –und nun?
Agile Coffeebreak  Team agil –und nun?Agile Coffeebreak  Team agil –und nun?
Agile Coffeebreak Team agil –und nun?Ayelt Komus
 
Process partner slides
Process partner slidesProcess partner slides
Process partner slidessocialmediapp
 
Burn your Businessplan: Vortrag mit Prof. Dr. Michael Seidel
Burn your Businessplan: Vortrag mit Prof. Dr. Michael SeidelBurn your Businessplan: Vortrag mit Prof. Dr. Michael Seidel
Burn your Businessplan: Vortrag mit Prof. Dr. Michael SeidelHermann Hohenberger
 
Der Weg in Richtung SAP Business Technology Platform - Herausforderungen und...
 Der Weg in Richtung SAP Business Technology Platform - Herausforderungen und... Der Weg in Richtung SAP Business Technology Platform - Herausforderungen und...
Der Weg in Richtung SAP Business Technology Platform - Herausforderungen und...IBsolution GmbH
 

Ähnlich wie Zum Beispiel ein Test (20)

sitacon - Solutions in Tourism
sitacon - Solutions in Tourism sitacon - Solutions in Tourism
sitacon - Solutions in Tourism
 
Continuous Relaunch - Impulsvortrag auf der relaunch Konferenz 2014
Continuous Relaunch - Impulsvortrag auf der relaunch Konferenz 2014Continuous Relaunch - Impulsvortrag auf der relaunch Konferenz 2014
Continuous Relaunch - Impulsvortrag auf der relaunch Konferenz 2014
 
Hilfe, meine Organisation ist digital und agil!
Hilfe, meine Organisation ist digital und agil!Hilfe, meine Organisation ist digital und agil!
Hilfe, meine Organisation ist digital und agil!
 
Excel ade: Revolutionieren Sie Ihr ESG-Reporting
Excel ade: Revolutionieren Sie Ihr ESG-ReportingExcel ade: Revolutionieren Sie Ihr ESG-Reporting
Excel ade: Revolutionieren Sie Ihr ESG-Reporting
 
Skalierte agile Methoden und Lean für das IT Demand- und Portfoliomanagment
Skalierte agile Methoden und Lean für das IT Demand- und PortfoliomanagmentSkalierte agile Methoden und Lean für das IT Demand- und Portfoliomanagment
Skalierte agile Methoden und Lean für das IT Demand- und Portfoliomanagment
 
Busines Cases __ tekom-Jahrestagung 2014
Busines Cases __ tekom-Jahrestagung 2014Busines Cases __ tekom-Jahrestagung 2014
Busines Cases __ tekom-Jahrestagung 2014
 
VDC-Jahresbericht 2013
VDC-Jahresbericht 2013VDC-Jahresbericht 2013
VDC-Jahresbericht 2013
 
Tisson & Company IT Management - Architektur
Tisson & Company IT Management - ArchitekturTisson & Company IT Management - Architektur
Tisson & Company IT Management - Architektur
 
Brennglas Corona
Brennglas CoronaBrennglas Corona
Brennglas Corona
 
Stars to road sbb svenkrause
Stars to road sbb svenkrauseStars to road sbb svenkrause
Stars to road sbb svenkrause
 
Beidhändiges Projektportfoliomanagement – Mit Stacey, Lean und Scaled Agile e...
Beidhändiges Projektportfoliomanagement – Mit Stacey, Lean und Scaled Agile e...Beidhändiges Projektportfoliomanagement – Mit Stacey, Lean und Scaled Agile e...
Beidhändiges Projektportfoliomanagement – Mit Stacey, Lean und Scaled Agile e...
 
Design Thinking - Arbeitsform für den Wandel
Design Thinking - Arbeitsform für den WandelDesign Thinking - Arbeitsform für den Wandel
Design Thinking - Arbeitsform für den Wandel
 
Juni 2015: The Lean Startup / Vorlesung "Entrepreneurship & Intrapreneurship"...
Juni 2015: The Lean Startup / Vorlesung "Entrepreneurship & Intrapreneurship"...Juni 2015: The Lean Startup / Vorlesung "Entrepreneurship & Intrapreneurship"...
Juni 2015: The Lean Startup / Vorlesung "Entrepreneurship & Intrapreneurship"...
 
Agile BI in der Praxis - Agiles Testen
Agile BI in der Praxis - Agiles TestenAgile BI in der Praxis - Agiles Testen
Agile BI in der Praxis - Agiles Testen
 
- Erfolgsfaktoren im Projektmanagement - Studienergebnisse und praktische Emp...
- Erfolgsfaktoren im Projektmanagement - Studienergebnisse und praktische Emp...- Erfolgsfaktoren im Projektmanagement - Studienergebnisse und praktische Emp...
- Erfolgsfaktoren im Projektmanagement - Studienergebnisse und praktische Emp...
 
The Lean Startup - Growth Hacking, Traction
The Lean Startup - Growth Hacking, TractionThe Lean Startup - Growth Hacking, Traction
The Lean Startup - Growth Hacking, Traction
 
Agile Coffeebreak Team agil –und nun?
Agile Coffeebreak  Team agil –und nun?Agile Coffeebreak  Team agil –und nun?
Agile Coffeebreak Team agil –und nun?
 
Process partner slides
Process partner slidesProcess partner slides
Process partner slides
 
Burn your Businessplan: Vortrag mit Prof. Dr. Michael Seidel
Burn your Businessplan: Vortrag mit Prof. Dr. Michael SeidelBurn your Businessplan: Vortrag mit Prof. Dr. Michael Seidel
Burn your Businessplan: Vortrag mit Prof. Dr. Michael Seidel
 
Der Weg in Richtung SAP Business Technology Platform - Herausforderungen und...
 Der Weg in Richtung SAP Business Technology Platform - Herausforderungen und... Der Weg in Richtung SAP Business Technology Platform - Herausforderungen und...
Der Weg in Richtung SAP Business Technology Platform - Herausforderungen und...
 

Zum Beispiel ein Test

  • 1. © OPITZ CONSULTING GmbH 2013 Seite 1Zum Beispiel ein Test Zum Beispiel ein Test Beispiele als Grundlage für Anforderungsanalyse, Spezifikation und Implementierung
  • 2. © OPITZ CONSULTING GmbH 2013 Seite 2Zum Beispiel ein Test Zu meiner Person Torsten Mandry Solution Architect OPITZ CONSULTING Deutschland GmbH Entwurf und Entwicklung von Enterprise Java Anwendungen Anforderungsanalyse und automatisiertes Testen E-Mail: torsten.mandry@opitz-consulting.com Twitter: @torstenmandry Google: +torsten.mandry
  • 3. © OPITZ CONSULTING GmbH 2013 Seite 3Zum Beispiel ein Test Märkte Java SOA ORACLE BI/DWH Outtasking Kunden Branchen- übergreifend Über 600 Kunden Leistungs- angebot IT-Strategie Beratung Implementierung Betrieb Training Fakten Gründung 1990 400 Mitarbeiter 8 Standorte in D/PL Industrie / Versorger / Telekommunikation 29% Handel / Logistik / Dienstleistungen 29% 42% Öffentliche Auftraggeber / Banken & Versicherungen / Vereine & Verbände © OPITZ CONSULTING GmbH 2011
  • 4. © OPITZ CONSULTING GmbH 2013 Seite 4Zum Beispiel ein Test Agenda • Erfahrungen und Erkenntnisse • Verwendung von Beispielen • Vom Beispiel zum Test • Akzeptanztest Frameworks Foto: arquera@Flickr
  • 5. © OPITZ CONSULTING GmbH 2013 Seite 5Zum Beispiel ein Test Foto: Brady Withers@Flickr Erfahrungen und Erkenntnisse
  • 6. © OPITZ CONSULTING GmbH 2013 Seite 6Zum Beispiel ein Test Entwicklung eines neuen Features AnalystAuftraggeber Entwickler Anforderung(en) Spezifikation Implementierung
  • 7. © OPITZ CONSULTING GmbH 2013 Seite 7Zum Beispiel ein Test Häufiges Ergebnis Bild: dullhunk@Flickr
  • 8. © OPITZ CONSULTING GmbH 2013 Seite 8Zum Beispiel ein Test Spezifikation wird interpretiert Auftraggeber Analyst Entwickler
  • 9. © OPITZ CONSULTING GmbH 2013 Seite 9Zum Beispiel ein Test Was läuft schief? Wir spezifizieren missverständlich Wir verstehen „Problem“ des Kunden nicht Wir kennen die Kriterien des Kunden nicht Wir haben kein gemeinsames Verständnis Foto: Horia Varlan@Flickr
  • 10. © OPITZ CONSULTING GmbH 2013 Seite 10Zum Beispiel ein Test Beispiele Foto: jonny goldstein@Flickr
  • 11. © OPITZ CONSULTING GmbH 2013 Seite 11Zum Beispiel ein Test Foto: bridgells@photobucket.com ? ? ? Eine übliche Anforderung Die Afa einer Investition ergibt sich aus dem Investitionswert, linear verteilt über den Abschreibungszeitraum, beginnend mit dem Monat der Aktivierung!
  • 12. © OPITZ CONSULTING GmbH 2013 Seite 12Zum Beispiel ein Test Können Sie uns dazu ein Beispiel nennen? Wenn wir eine Investition im Wert von 600 TEUR getätigt haben, die am 01.01.2012 aktiviert wurde, dann folgt daraus, bei einer Abschreibungsdauer von 60 Monaten, eine monatliche AfA in Höhe von 10 TEUR und zwar von Jan/2012 bis Dez/2016.
  • 13. © OPITZ CONSULTING GmbH 2013 Seite 13Zum Beispiel ein Test Etwas anders formuliert… dann folgt daraus eine monatliche AfA in Höhe von 10 TEUR in der Zeit von Jan/2012 bis Dez/2016. Wenn wir die Afa berechnen Wir haben eine Investition im Wert von 600 TEUR aktiviert am 01.01.2012 und eine Abschreibungsdauer von 60 Monaten Ausgangssituation / -zustand Aktion / Ereignis Erwartetes Ergebnis
  • 14. © OPITZ CONSULTING GmbH 2013 Seite 14Zum Beispiel ein Test Beispiele helfen…  veranschaulichen / verdeutlichen  decken Fragen / Lücken auf  zwingen zum Nachdenken  führen zu weiteren / detaillierteren Beispielen  können nachgestellt werden Foto: therichbrooks@Flickr
  • 15. © OPITZ CONSULTING GmbH 2013 Seite 15Zum Beispiel ein Test …können aber schwierig sein  ungewohnt / erfordern Übung  komplexe Zusammenhänge  viele Einflussfaktoren / Vorbedingungen  was ist relevant, was nicht?  Auf das Wesentliche Konzentrieren Foto: andrewrennie@Flickr
  • 16. © OPITZ CONSULTING GmbH 2013 Seite 16Zum Beispiel ein Test „Nachspezifikation“ „Das haben wir doch alles schon mal besprochen!“ „Alles wie bisher, nur...“  Grundlegende Beispiele als Basis Foto: electricnerve@Flickr
  • 17. © OPITZ CONSULTING GmbH 2013 Seite 17Zum Beispiel ein Test Foto: anieto2k@Flickr Spezifikation wird durch Beispiele nicht einfacher… …sondern besser!
  • 18. © OPITZ CONSULTING GmbH 2013 Seite 18Zum Beispiel ein Test Specification by Example Beispiele als alleinige Spezifikation  alle relevante Funktionalität  vollständig mit Beispielen beschrieben  keine „Prosa“-Spezifikation mehr notwendig Foto: VickyvS@flickr.com
  • 19. © OPITZ CONSULTING GmbH 2013 Seite 19Zum Beispiel ein Test „sanfter“ Mittelweg Beispiele als Ergänzung zur Prosa-Spezifikation  Prosa  Problemstellung / Motivation  Rahmenbedingungen  Hintergründe  Beispiele  Verdeutlichung / Detaillierung  Sonder- / Randfälle  Konkretisierung Foto: tinyfroglet@Flickr
  • 20. © OPITZ CONSULTING GmbH 2013 Seite 20Zum Beispiel ein Test Beispiele als „Definition of Done“ Wenn alle definierten Beispiele erfolgreich durchlaufen werden ist das Feature fertig Foto: jayneandd@flickr.com
  • 21. © OPITZ CONSULTING GmbH 2013 Seite 21Zum Beispiel ein Test Vom Beispiel zum Test
  • 22. © OPITZ CONSULTING GmbH 2013 Seite 22Zum Beispiel ein Test public class InvestmentPosition extends Position { … public void calculateArmortisation() { if (initiationDate == null) throw new IllegalStateException("initiation date not set"); if (amount == null) throw new IllegalStateException("amount not set"); if (project == null) throw new IllegalStateException("project not set"); if (project.getStartDate() == null || project.getEndDate() == null) throw new IllegalStateException("project start/end date not set"); armortisation.clear(); int armortisationMonths = ProjectManagementApp.getInstance().getArmortisationMonths(); BigDecimal monthlyAmount = amount.divide(BigDecimal.valueOf(armortisationMonths)); for (int i = 0; i < armortisationMonths; i++) { Calendar monthYear = new GregorianCalendar(); monthYear.setTime(initiationDate); monthYear.add(Calendar.MONTH, i); int month = monthYear.get(Calendar.MONTH) + 1; int year = monthYear.get(Calendar.YEAR); armortisation.add(new PositionValue(this, month, year, monthlyAmount)); } } … } Code Beispiel
  • 23. © OPITZ CONSULTING GmbH 2013 Seite 23Zum Beispiel ein Test Unser Beispiel von eben dann folgt daraus eine monatliche AfA in Höhe von 10 TEUR in der Zeit von Jan/2012 bis Dez/2016. Wenn wir die Afa berechnen Wir haben eine Investition im Wert von 600 TEUR aktiviert am 01.01.2012 und eine Abschreibungsdauer von 60 Monaten Ausgangssituation / -zustand Aktion / Ereignis Erwartetes Ergebnis
  • 24. © OPITZ CONSULTING GmbH 2013 Seite 24Zum Beispiel ein Test JUnit Test @Test public void calculateArmortisationTest() { // Gegeben sei eine Investition InvestmentPosition investment = new InvestmentPosition("any position name"); // im Wert von 600 TEUR investment.setAmount(BigDecimal.valueOf(600000)); // aktiviert am 01.01.2012 investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); // und eine Abschreibungsdauer von 60 Monaten ProjectManagementApp.getInstance().setArmortisationMonths(60); // und noch einiges mehr... Project project = new Project("any project name"); project.addPosition(investment); project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime()); // wenn die Abschreibung berechnet wird investment.calculateArmortisation(); // dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR // in der Zeit von 01/2012 bis 12/2016 assertEquals("number of armortisation values", 60, investment.getArmortisation().size()); for (int i = 0; i < 60; i++) { PositionValue value = investment.getArmortisation().get(i); Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1); expectedMonthYear.add(Calendar.MONTH, i); assertEquals(format("value %d - month", i), expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth()); assertEquals(format("value %d - year", i), expectedMonthYear.get(Calendar.YEAR), value.getYear()); assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000), value.getAmount()); } }
  • 25. © OPITZ CONSULTING GmbH 2013 Seite 25Zum Beispiel ein Test JUnit Test @Test public void calculateArmortisationTest() { // Gegeben sei eine Investition InvestmentPosition investment = new InvestmentPosition("any position name"); // im Wert von 600 TEUR investment.setAmount(BigDecimal.valueOf(600000)); // aktiviert am 01.01.2012 investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); // und eine Abschreibungsdauer von 60 Monaten ProjectManagementApp.getInstance().setArmortisationMonths(60); // und noch einiges mehr... Project project = new Project("any project name"); project.addPosition(investment); project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime()); // wenn die Abschreibung berechnet wird investment.calculateArmortisation(); // dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR // in der Zeit von 01/2012 bis 12/2016 assertEquals("number of armortisation values", 60, investment.getArmortisation().size()); for (int i = 0; i < 60; i++) { PositionValue value = investment.getArmortisation().get(i); Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1); expectedMonthYear.add(Calendar.MONTH, i); assertEquals(format("value %d - month", i), expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth()); assertEquals(format("value %d - year", i), expectedMonthYear.get(Calendar.YEAR), value.getYear()); assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000), value.getAmount()); } } // Gegeben sei eine Investition InvestmentPosition investment = new InvestmentPosition("any position name"); // im Wert von 600 TEUR investment.setAmount(BigDecimal.valueOf(600000)); // aktiviert am 01.01.2012 investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); // und eine Abschreibungsdauer von 60 Monaten ProjectManagementApp.getInstance().setArmortisationMonths(60);
  • 26. © OPITZ CONSULTING GmbH 2013 Seite 26Zum Beispiel ein Test JUnit Test @Test public void calculateArmortisationTest() { // Gegeben sei eine Investition InvestmentPosition investment = new InvestmentPosition("any position name"); // im Wert von 600 TEUR investment.setAmount(BigDecimal.valueOf(600000)); // aktiviert am 01.01.2012 investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); // und eine Abschreibungsdauer von 60 Monaten ProjectManagementApp.getInstance().setArmortisationMonths(60); // und noch einiges mehr... Project project = new Project("any project name"); project.addPosition(investment); project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime()); // wenn die Abschreibung berechnet wird investment.calculateArmortisation(); // dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR // in der Zeit von 01/2012 bis 12/2016 assertEquals("number of armortisation values", 60, investment.getArmortisation().size()); for (int i = 0; i < 60; i++) { PositionValue value = investment.getArmortisation().get(i); Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1); expectedMonthYear.add(Calendar.MONTH, i); assertEquals(format("value %d - month", i), expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth()); assertEquals(format("value %d - year", i), expectedMonthYear.get(Calendar.YEAR), value.getYear()); assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000), value.getAmount()); } } // und noch einiges mehr... Project project = new Project("any project name"); project.addPosition(investment); project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime());
  • 27. © OPITZ CONSULTING GmbH 2013 Seite 27Zum Beispiel ein Test JUnit Test @Test public void calculateArmortisationTest() { // Gegeben sei eine Investition InvestmentPosition investment = new InvestmentPosition("any position name"); // im Wert von 600 TEUR investment.setAmount(BigDecimal.valueOf(600000)); // aktiviert am 01.01.2012 investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); // und eine Abschreibungsdauer von 60 Monaten ProjectManagementApp.getInstance().setArmortisationMonths(60); // und noch einiges mehr... Project project = new Project("any project name"); project.addPosition(investment); project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime()); // wenn die Abschreibung berechnet wird investment.calculateArmortisation(); // dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR // in der Zeit von 01/2012 bis 12/2016 assertEquals("number of armortisation values", 60, investment.getArmortisation().size()); for (int i = 0; i < 60; i++) { PositionValue value = investment.getArmortisation().get(i); Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1); expectedMonthYear.add(Calendar.MONTH, i); assertEquals(format("value %d - month", i), expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth()); assertEquals(format("value %d - year", i), expectedMonthYear.get(Calendar.YEAR), value.getYear()); assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000), value.getAmount()); } } // wenn die Abschreibung berechnet wird investment.calculateArmortisation();
  • 28. © OPITZ CONSULTING GmbH 2013 Seite 28Zum Beispiel ein Test JUnit Test @Test public void calculateArmortisationTest() { // Gegeben sei eine Investition InvestmentPosition investment = new InvestmentPosition("any position name"); // im Wert von 600 TEUR investment.setAmount(BigDecimal.valueOf(600000)); // aktiviert am 01.01.2012 investment.setInitiationDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); // und eine Abschreibungsdauer von 60 Monaten ProjectManagementApp.getInstance().setArmortisationMonths(60); // und noch einiges mehr... Project project = new Project("any project name"); project.addPosition(investment); project.setStartDate(new GregorianCalendar(2012, 1 - 1, 1).getTime()); project.setEndDate(new GregorianCalendar(2013, 12 - 1, 31).getTime()); // wenn die Abschreibung berechnet wird investment.calculateArmortisation(); // dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR // in der Zeit von 01/2012 bis 12/2016 assertEquals("number of armortisation values", 60, investment.getArmortisation().size()); for (int i = 0; i < 60; i++) { PositionValue value = investment.getArmortisation().get(i); Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1); expectedMonthYear.add(Calendar.MONTH, i); assertEquals(format("value %d - month", i), expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth()); assertEquals(format("value %d - year", i), expectedMonthYear.get(Calendar.YEAR), value.getYear()); assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000), value.getAmount()); } } // dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR // in der Zeit von 01/2012 bis 12/2016 assertEquals("number of armortisation values", 60, investment.getArmortisation().size()); for (int i = 0; i < 60; i++) { PositionValue value = investment.getArmortisation().get(i); Calendar expectedMonthYear = new GregorianCalendar(2012, 1 - 1, 1); expectedMonthYear.add(Calendar.MONTH, i); assertEquals(format("value %d - month", i), expectedMonthYear.get(Calendar.MONTH) + 1, value.getMonth()); assertEquals(format("value %d - year", i), expectedMonthYear.get(Calendar.YEAR), value.getYear()); assertEquals(format("value %d - amount", i), BigDecimal.valueOf(10000), value.getAmount()); }
  • 29. © OPITZ CONSULTING GmbH 2013 Seite 29Zum Beispiel ein Test Testdata Factory erzeugt Domänen-Objekte gefüllt mit Default-Daten vollständig valide Zwei nützliche Helfer Configurable Entity ermöglich konfigurieren Fluent Interface Foto: florianric@Flickr
  • 30. © OPITZ CONSULTING GmbH 2013 Seite 30Zum Beispiel ein Test Configurable Entity public class ConfigurableInvestmentPosition extends InvestmentPosition { public ConfigurableInvestmentPosition(String name) { super(name); } public ConfigurableInvestmentPosition withAmount(double amount) { this.setAmount(BigDecimal.valueOf(amount)); return this; } public ConfigurableInvestmentPosition withInitiationDate(Date initiationDate) { this.setInitiationDate(initiationDate); return this; } public ConfigurableInvestmentPosition withInitiationDate(int day, int month, int year) { this.setInitiationDate(DateBuilder.givenDate(day, month, year).toDate(); return this; } … }
  • 31. © OPITZ CONSULTING GmbH 2013 Seite 31Zum Beispiel ein Test Testdata Factory public class InvestmentPositionFactory { private static final String DEFAULT_NAME = "any position name"; private static final double DEFAULT_AMOUNT = 100000; private static final Date DEFAULT_INITIATION_DATE = DateBuilder.givenDate(1, 1, 2012).toDate(); private static final String DEFAULT_COST_CENTER = "66666"; public static ConfigurableInvestmentPosition createDefault() { ConfigurableInvestmentPosition investmentPosition = new ConfigurableInvestmentPosition(DEFAULT_NAME) .withAmount(DEFAULT_AMOUNT) .withInitiationDate(DEFAULT_INITIATION_DATE) .withCostCenter(DEFAULT_COST_CENTER); Project project = ProjectFactory.createDefault(); project.addPosition(investmentPosition); return investmentPosition; } }
  • 32. © OPITZ CONSULTING GmbH 2013 Seite 32Zum Beispiel ein Test Besserer JUnit Test @Test public void betterCalculateArmortisationTest() { // Gegeben sei eine Investition // im Wert von 600 TEUR // aktiviert am 01.01.2012 InvestmentPosition investment = InvestmentPositionFactory.createDefault() .withAmount(600000) .withInitiationDate(1, 1, 2012); // und eine Abschreibungsdauer von 60 Monaten ProjectManagementApp.getInstance().setArmortisationMonths(60); // wenn die Abschreibung berechnet wird investment.calculateArmortisation(); // dann folgt daraus eine monatliche Abschreibung in Höhe von 10 TEUR // in der Zeit von 01/2012 bis 12/2016 assertThat(investment.getArmortisation(), hasConstantAmount(10000)); assertThat(investment.getArmortisation(), containsMonthsFromTo( 1, 2012, 12, 2016)); } Hamcrest Matchers
  • 33. © OPITZ CONSULTING GmbH 2013 Seite 33Zum Beispiel ein Test Akzeptanztest Frameworks http://jbehave.org/ http://cukes.info/ http://www.concordion.org/
  • 34. © OPITZ CONSULTING GmbH 2013 Seite 34Zum Beispiel ein Test Akzeptanztest Frameworks http://jbehave.org/
  • 35. © OPITZ CONSULTING GmbH 2013 Seite 35Zum Beispiel ein Test User Story calculate_armortisation_of_an_investment_position.story Narrative: As a user I want to calculate the armortisation of an investment position So that I can see the monthly armortisation amounts Scenario: calculate armortisation for 600000 EUR and 60 months Given an investment position with amount 600000 EUR initiated on 01.01.2012 And an armortisation time of 60 months When I calculate the armortisation of the investment position Then the monthly armortisation amount is 10000 EUR And the armortisation runs from 01/2012 to 12/2016 Scenario: calculate armortisation for 30000 EUR and 24 months Given an investment position with amount 30000 EUR initiated on 01.01.2012 And an armortisation time of 24 months When I calculate the armortisation of the investment position Then the monthly armortisation amount is 1250 EUR And the armortisation runs from 01/2012 to 12/2013
  • 36. © OPITZ CONSULTING GmbH 2013 Seite 36Zum Beispiel ein Test Mapped Steps public class CalculateArmortisationSteps { private InvestmentPosition investment; @Given("an investment position with amount $amount EUR initiated on $initiationDate") public void setupInvestmentPosition(double amount, String initiationDate) { investment = InvestmentPositionFactory.createDefault() .withAmount(amount) .withInitiationDate(initiationDate); } @Given("an armortisation time of $months months") public void setupArmortisationPeriod(int months) { ProjectManagementApp.getInstance().setArmortisationMonths(months); } @When("I calculate the armortisation of the investment position") public void calculateArmortisation() { investment.calculateArmortisation(); } @Then("the monthly armortisation amount is $amount EUR") public void assertMonthlyArmortisationAmount(double amount) { assertThat(investment.getArmortisation(), hasConstantAmount(amount)); } … }
  • 37. © OPITZ CONSULTING GmbH 2013 Seite 37Zum Beispiel ein Test Testergebnis
  • 38. © OPITZ CONSULTING GmbH 2013 Seite 38Zum Beispiel ein Test Fehlerfall
  • 39. © OPITZ CONSULTING GmbH 2013 Seite 39Zum Beispiel ein Test Akzeptanztest Frameworks http://www.concordion.org/
  • 40. © OPITZ CONSULTING GmbH 2013 Seite 40Zum Beispiel ein Test Spezifikation <html xmlns:concordion="http://www.concordion.org/2007/concordion"> <body> <h1>Calculate armortisation of an investment position</h1> … <div class="example"> <h3>Scenario: calculate armortisation for 600000 EUR and 60 months</h3> <p concordion:execute="#investment = setupInvestmentPosition(#amount, #initiationDate)"> Given an investment position with amount <strong concordion:set="#amount">600000</strong> EUR initiated on <strong concordion:set="#initiationDate">01.01.2012</strong></p> <p concordion:execute="setupArmortisationTime(#months)"> And an armortisation time of <strong concordion:set="#months">60</strong> months</p> <p>When I <strong concordion:execute="calculateArmortisation(#investment)">calculate the armortisation of the investment position</strong></p> <p>Then the monthly armortisation amount is <strong concordion:assertEquals= "monthlyArmortisationAmount(#investment)">10000,00</strong> EUR</p> <p>And the armortisation runs from <strong concordion:assertEquals="armortisationStart(#investment)">01/2012</strong> to <strong concordion:assertEquals="armortisationEnd(#investment)">12/2016</strong> …
  • 41. © OPITZ CONSULTING GmbH 2013 Seite 41Zum Beispiel ein Test Fixture @RunWith(ConcordionRunner.class) public class CalculateArmortisationOfAnInvestmentPositionFixture { public InvestmentPosition setupInvestmentPosition(double amount, String initiationDate) { return InvestmentPositionFactory.createDefault() .withAmount(amount) .withInitiationDate(initiationDate); } public void setupArmortisationTime(int months) { ProjectManagementApp.getInstance().setArmortisationMonths(months); } public void calculateArmortisation(InvestmentPosition investment) { investment.calculateArmortisation(); } …
  • 42. © OPITZ CONSULTING GmbH 2013 Seite 42Zum Beispiel ein Test Fixture public String armortisationStart(InvestmentPosition investment) { PositionValue firstValue = getSortedPositionValues(investment).get(0); return format("%02d/%4d", firstValue.getMonth(), firstValue.getYear()); } public String armortisationEnd(InvestmentPosition investment) { List<PositionValue> values = getSortedPositionValues(investment); PositionValue lastValue = values.get(values.size() - 1); return format("%02d/%4d", lastValue.getMonth(), lastValue.getYear()); } public boolean isContinousArmortisation(InvestmentPosition investment) { return containsMonthsFromTo(armortisationStart(investment), armortisationEnd(investment)).matches(investment.getArmortisation()); } …
  • 43. © OPITZ CONSULTING GmbH 2013 Seite 43Zum Beispiel ein Test Testergebnis
  • 44. © OPITZ CONSULTING GmbH 2013 Seite 44Zum Beispiel ein Test Fehlerfall
  • 45. © OPITZ CONSULTING GmbH 2013 Seite 45Zum Beispiel ein Test Fehlerfall
  • 46. © OPITZ CONSULTING GmbH 2013 Seite 46Zum Beispiel ein Test Lebende Spezifikation  Beschreibung der vollständigen Funktionalität  in Form von automatisierten Akzeptanztests
  • 47. © OPITZ CONSULTING GmbH 2013 Seite 47Zum Beispiel ein Test Referenzen  Code-Beispiele: https://github.com/torstenmandry/testing-samples  Torsten Mandry: “Configurable entities with fluent interface”, http://javandry.blogspot.de/2012/11/configurable-entities-with- fluent.html, 2012  Gojko Adzic: „Bridging the Communication Gap – Specification by Example and Agile Acceptance Testing”, Neuri Limited, 2011  JBehave: http://jbehave.org/  Cucumber: http://cukes.info/  Concordion: http://www.concordion.org/
  • 48. © OPITZ CONSULTING GmbH 2013 Seite 48Zum Beispiel ein Test Danke für Ihre Aufmerksamkeit