Composition & Unit testing with MS test

Слайд 2

Agenda

Composition vs Inheritance?
Examples
Unit testing
TDD
Creating MS Test project
Assert class
Examples

Agenda Composition vs Inheritance? Examples Unit testing TDD Creating MS Test project Assert class Examples

Слайд 3

Composition vs Inheritance

Object Composition is a way to combine simple objects or

Composition vs Inheritance Object Composition is a way to combine simple objects
data types into more complex ones.
Inheritance is a way to form new classes by using classes that have already been defined.
Composition realizes ”has a” relationship: A car "has an" engine, a person "has a" name, etc.
Inheritance realizes ”is a” relationship. A car "is a" vehicle, a student "is a" person, etc.

Слайд 4

Example 1. Point and Triangle

Example 1. Point and Triangle

Слайд 5

Example 2. Slide, Presentation

Example 2. Slide, Presentation

Слайд 6

Task-Homework 1

Create struct Point:
- fields x and y,
- method

Task-Homework 1 Create struct Point: - fields x and y, - method
Distance() to calculate distance between points
- method ToString(), which return the Point in format "(x,y)"
Create class Triangle:
- fields vertex1, vertex2, vertex3 of type Point
- constructors
- methods Perimeter(), Square(), Print()
In the Main() create list of 3 triangles and write into console the information about these shapes.
*Print the triangle with vertex which is the closest to origin (0,0)

Слайд 7

Unit testing with MS test

Unit testing with MS test

Слайд 8

Unit Testing

Unit testing is a procedure used to validate that individual units

Unit Testing Unit testing is a procedure used to validate that individual
of source code (methods, properties, classes) are working properly.

Unit tests

Production Code

Слайд 9

Test-Driven Development (TDD)

The traditional way of writing unit tests

Test-driven development

Test-Driven Development (TDD) The traditional way of writing unit tests Test-driven development

Слайд 10

Unit-testing frameworks

UTF for .NET:
MSTest
NUnit
XUnit

Unit-testing frameworks UTF for .NET: MSTest NUnit XUnit …

Слайд 11

Creating Unit Tests

Creating Unit Tests

Слайд 12

Kinds of Assert Classes

Microsoft.VisualStudio.TestTools.UnitTesting namespace:
class Assert
In your test method, you can

Kinds of Assert Classes Microsoft.VisualStudio.TestTools.UnitTesting namespace: class Assert In your test method,
call any number of methods of the Assert class, such as Assert.AreEqual(). The Assert class has many methods to choose from, and many of those methods have several overloads.
class CollectionAssert
Use the CollectionAssert class to compare collections of objects, and to verify the state of one or more collections.
class StringAssert
Use the StringAssert class to compare strings. This class contains a variety of useful methods such as StringAssert.Contains, StringAssert.Matches, and StringAssert.StartsWith.

Слайд 13

public static class Assert

public static class Assert

Слайд 14

Example 1. Testing Bank project

Example 1. Testing Bank project

Слайд 15

Create project and Unit test example

1. Create project MyCalcLib

2. Right click on

Create project and Unit test example 1. Create project MyCalcLib 2. Right
Solution
Add
Test “MyCalcTests”
3. Right click on References
Add References
project “MyCalcLib”

Слайд 16

Create project and Unit test example

After this click Build Solution

Create project and Unit test example After this click Build Solution
Имя файла: Composition-&-Unit-testing-with-MS-test.pptx
Количество просмотров: 60
Количество скачиваний: 0