57
07. November, Zürich-Oerlikon ALM & DevOps Day 24. September 2015, Zürich Oerlikon

ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

07. November, Zürich-Oerlikon

ALM & DevOps Day24. September 2015, Zürich Oerlikon

Page 2: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Testing mit Visual Studio

Rolf Wenger

CTO

weroSoft AG

Page 3: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Agenda

weroSoft ist in den Bereichen Beratung, Entwicklung und Ausbildung auf der Basis der .NET-Technologien tätig

Basierend auf unserem eigenen Application Framework entwickeln wir kundenspezifische Client-Server-Anwendungen

Langjährige Ausbildungstätigkeiten für Softwareentwicklermittels Firmenkursen und .NET CAS an der Berner Fachhochschule

Durchführung von kundenorientierten E-Learning Projekten in den Bereichen Dienstleistung und Industrie

http://www.weroSoft.net

Page 4: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Agenda

1. Warum testen

2. Wann testen

3. Was testen

4. Wie testen

5. Gehört Testen zur Architektur

6. Unterstützung in Visual Studio 2015

Agenda

Page 5: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Kapitel 1

Warum testen

Page 6: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Qualitätssicherung ohne Ende

Maschinenteile werden gemessen

Lebensmittel werden gewogen

Brücken werden belastet

Wissen wird geprüft

Beratung wird beurteilt

Page 7: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Beispiel Fertigung

Page 8: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Szenenwechsel

int variable = 1;

int result = variable++ + variable++ + variable++;

Welcher Wert hat die Variable «result»?

Page 9: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Warum testen wir?

Weil wir zufriedene Kunden wollen!

Page 10: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Kapitel 2

Wann testen

Page 11: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Der Regelkreis

Page 12: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Der Entwickler

Page 13: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Wann testen wir?

Auf mehreren Ebenen während der gesamten Entwicklung – und das unaufgefordert und zielorientiert!

Page 14: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Kapitel 3

Was testen

Page 15: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Happy Path Test

Testen der Anforderung unter Idealbedingungen

Alles soll so funktionieren wie angedacht

Keine Ausnahmen

Keine Varianten

Einmalige Ausführung

Optimale Unterstützung durch Visual Studio 2015

Page 16: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Alternativ Path Tests

Testen der Anforderung durch Nutzung von alternativen Code Pfaden

Permutationen von Varianten

Keine Ausnahmen

Einmalige Ausführung pro Variante

Optimale Unterstützung durch Visual Studio 2015

Page 17: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Exceptional Path Tests

Testen der Anforderung durch gezielte Provokation von Fehlern

Permutationen von Fehlervarianten

Ausnahmen / Ausnahmetypen und Meldungen

Einmalige Ausführung pro Variante

Unterstützung durch Visual Studio 2015

Page 18: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Regression Tests

Testen der wiederholten, korrekten Ausführung des Codes

Sicherstellen, dass nach Änderungen und Ergänzungen keine Seiteneffekte auftreten

Unterstützung durch Visual Studio 2015

Page 19: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Was testen wir?

Die gesamte mögliche Codeausführung in allen Varianten und Lebenslagen!

Page 20: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Kapitel 4

Wie testen

Page 21: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Testpyramide

Unit Test

Integration Test

Acceptance Test

Page 22: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Unit Test

Fundament der Qualitätssicherung

In der Verantwortung der Entwickler

Messung der Codeabdeckung

Kostengünstig

Kann sehr grosse Menge erreichen

Eine 100% Automation ist anzustreben

Page 23: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Integration Test

Testen der Zusammenarbeit der Komponenten

In der Verantwortung der Tester

Mittleres Automatisierungspotential

Erfordert oft Produktinstallation

Mittlere Menge

Automatisierbar aber auch oft manuell ausgeführt

Page 24: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Acceptance Test

Testen des gesamten Systems

In der Verantwortung der Tester

Teurere Automatisierung

Erfordert zwingend Produktinstallation

Kleinste Menge, Testen der Anforderungen / UC

Automatisierbar aber auch oft manuell ausgeführt

Page 25: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Wie testen wir?

Indem wir für unser Projekt die Testpyramide umsetzen und idealtypisch vollautomatisiert alle Tests jede Nacht ausführen!

Page 26: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Kapitel 5

Gehört Testen zur Architektur

Page 27: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Frage 1

Wie viele Tests brauche ich um das Zahlenschloss zu öffnen?

Page 28: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Frage 2

Wie viele Tests brauche ich um das Zahlenschloss zu öffnen?

Page 29: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Frage 3

Wie wollen Sie den Netzteil von dem Gerät testen?

Page 30: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Frage 4

Wie will weroSoft testen,

dass die Webseite in allen

Browsern korrekt ange-

zeigt wird?

Page 31: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Antworten auf alle Fragen

1. Zerlegung des Systems in Baugruppen

2. Zerlegen der Baugruppen in Komponenten

3. Erstellen der Komponenten

4. Testen der Komponenten

5. Zusammenbau der Komponenten zu Baugruppen

6. Testen der Baugruppe

7. Zusammenbau zum Produkt

8. Testen des Produkts

Page 32: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Wir erinnern uns

Page 33: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Übersetzung für Software-Engineers

Baugruppe

Page 34: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

… bis zur kleinsten Einheit …

Prüfling

MyClass.Method()

Project Assembly

Unit Test

Unit Test Assembly

Mock

Simulation eines

vom Prüfling

angesprochenen

Objekts.

Project oder

sonstige Assembly

Page 35: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Die Testautomation

Visual

Studio

2015

oder

mstest.exeUnit Test

Framework

Unit Test Prüfling

Page 36: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Gehört Testen zur Architektur?

Definitiv ja!

Testen soll bereits im Lösungsansatz Platz finden!

Schichtenmodell

Komponentenmodell

Ersetzbarkeit (Mocking / Simulation)

Page 37: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Kapitel 6

Unterstützung in Visual Studio 2015

Page 38: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Generelle Unterstützung

Classic Unit Tests Happy Path Unit Tests

Alternative Path Unit Tests

Exception Path Unit Tests

Data-Driven Unit Tests

Coded UI Tests (nur Visual Studio Enterprise)

IntelliTesting (nur Visual Studio Enterprise)

Page 39: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Scenariopublic string SimpleMethod(string argument)

{

if (string.IsNullOrEmpty(argument))

throw new ArgumentNullException("argument");

int indexSpace = argument.IndexOf(" ");

switch(indexSpace)

{

case -1:

return argument;

case 0:

return string.Empty;

default:

return argument.Substring(0, indexSpace);

}

}

Page 40: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Happy Path Unit Test[TestClass()]

public class SimpleDemoTypeTests

{

[TestMethod()]

public void HappyPathSimpleMethodTest()

{

string expectedString = "Testing";

string resultingString = null;

SimpleDemoType sample = new SimpleDemoType();

resultingString = sample.SimpleMethod(expectedString);

Assert.AreEqual<string>(expectedString, resultingString);

}

Page 41: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Alternative Path Test[TestMethod()]

public void AlternativePathSimpleMethodTest()

{

string parameter = "Testing an alternative path";

string expectedString = "Testing";

string resultingString = null;

SimpleDemoType sample = new SimpleDemoType();

resultingString = sample.SimpleMethod(parameter);

Assert.AreEqual<string>(expectedString, resultingString);

}

Page 42: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Exception Test[ExpectedException(typeof(ArgumentNullException))]

[TestMethod()]

public void ExceptionPathSimpleMethodTest()

{

string parameter = null;

string resultingString = null;

SimpleDemoType sample = new SimpleDemoType();

resultingString = sample.SimpleMethod(parameter);

// On using the attribute ExpectedExceptionAttribute you must

// not assert the test. It is automatically asserted to the

// expected exception type.

}

Page 43: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Data driven Test[DeploymentItem("DataDrivenTestDemo.xml")]

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", // Type of data source

"DataDrivenTestDemo.xml", // Name of XML file

"SimpleTestData", // Name of table element

DataAccessMethod.Sequential)] // Kind of data access

[TestMethod()]

public void DataDrivenSimpleMethodTest()

{

string parameter = TestContext.DataRow["parameter"] as string;

string expectedString = TestContext.DataRow["expected"] as string;

string exceptionType = TestContext.DataRow["exceptionType"] as string;

string resultingString = null;

if (parameter == "null") parameter = null;

SimpleDemoType sample = new SimpleDemoType();

Page 44: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Data driven Test…

try

{

resultingString = sample.SimpleMethod(parameter);

Assert.AreEqual<string>(expectedString, resultingString);

}

catch (ArgumentNullException exception)

{

if (string.IsNullOrWhiteSpace(exceptionType))

Assert.Fail("An unexpected exception has been caught.");

else

if (string.Compare(exception.GetType().Name, exceptionType, true) != 0)

Assert.Fail("Type is not as expected.");

}

}

Page 45: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Coded UI Test (nur Visual Studio Enterprise)

Testen von Benutzeroberflächen

Unterstützt Forms, WPF und Web

Tests können generiert werden

In der Praxis ist eine händische Codierung erfolgreicher

Integration für die Testausführung

Page 46: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

IntelliTest (nur Visual Studio Enterprise)

Neustes Kind der Testumgebung

Integriert in Visual Studio 2015

Generiert den Unit Test aufgrund des Nutzcodes Instant Ausführung möglich

Generierung des Unit Tests und Integration in Automation ist möglich

Ziel 100% Codeabdeckung

Page 47: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

IntelliTest – direkte Ausführung

Page 48: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

IntelliTest – Resultat der Ausführung

Page 49: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

IntelliTest – Create Unit Test

1. Generieren anstelle von ausführen

2. Erzeugt eine PEX1-Assembly

3. Generierten Test ausführen

4. Erzeugt die Test Methoden

5. Prüfen der Codeabdeckung

6. Bereit für die Testautomation

Page 50: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Testüberwachung Visual Studio 2015

Test Explorer zeigt alle Unit Tests

Ausführung einzeln / mehrere / alle

Ausführung mit oder ohne Debugging

Verschiedene Sortierungen

Messen der Codeabdeckung (Enterprise)

Page 51: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Test Explorer

Page 52: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Testüberwachung TFS 2015

Page 53: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Testdetails im TFS

Page 54: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Kapitel 7

Zusammenfassung

Page 55: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Zusammenfassung

Das sind meine 3 wichtigsten Punkte, die ich Ihnen weitergeben will:

1. Testen gehört zur Entwicklung wie das Lesen der News zum Tag

2. Testen ist anspruchsvoll und muss bereits in der Architektur berücksichtigt werden

3. Visual Studio und der TFS unterstützt dieses Vorhaben in allen Belangen

Page 56: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie

Besten Dank für Ihre Aufmerksamkeit

Für allfällige Fragen stehen wir Ihnen jederzeit gerne zur Verfügung:

weroSoft AG

Obere Zollgasse 75

3072 Ostermundigen

[email protected]

Page 57: ALM & DevOps Day - download.microsoft.comdownload.microsoft.com/documents/de-ch/almdays/Testing with Visual Studio.pdf · Agenda 1. Warum testen 2. Wann testen 3. Was testen 4. Wie