Using and Testing Classes Slides
Using and Testing Classes Slides
Testing Classes
Gill Cleeren
CTO Xpirit Belgium
@gillcleeren
Overview
Working with objects
Adding static members
Exploring the interface
Writing unit tests
Working with Objects
From Classes to Objects
Object 1
Color: pink
Object 2
Color: blue
Class Object 3
Color is a field Color: green
Classes Are Reference Types
Stack Heap
int a = 1;
a=1
int b = 5;
b=5 o (obj)
object o =
new object(); o (ref)
Creating a New Object
Assignment operator
Creating objects
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public Product()
{
}
}
Validate result
Advantages of Unit Tests
//Act
product.IncreaseStock(100);
//Assert
Assert.Equal(100, product.AmountInStock);
}
Demo