ZiBaT => Peter Levinsky => SWD => exercise

Unit testing

Updated : 2016-11-18


Unit testing

Idea : To implement and run your first unit test
Background:

Test Console applications

Exercise 1 : Make a simple model class Person

Make a new console project

Make a folder named 'model'

Create a class 'person' in the model-folder (or in c# terms namespace)
this class must be public, have two properties Name and Age, have a constructor and the 'ToString' method

For the two properties you have these constraints

  1. The Name is not null nor empty
  2. The Age is the range 0-130.

If these constraints are violated the class throws an ArgumentException.

Exercise 2 : Make a Unit test for the class Person

In the same solution make a new project - choose TEST -> UnitTestProject.

Make a reference to your model class (i.e. add reference -> pick from solution your project).

Make appropriate testcases i.e. TestMethods to test the Person class (a round 8-9 testcases)

Exercise 3 : Make a Unit test for Exercise 22 (C# Note exercises)

Have your exercise 21 programmed. Modify the BookCatalog class to be public.

In the same solution make a new project - choose TEST -> UnitTestProject.

Make a reference to your classes (i.e. add reference -> pick from solution your project).

Make an UnitTest for the class BookCatalog and test the three methods AddBook, LookupBook, PrintAllBooks.

 

Test App applications

Exercise 4: Make a Unit Test for the MVVM-App (simpleMVVM + GIT-Repository)

Take the Simple-MVVM app.

In the same solution make a new project - choose Windows -> Universal -> Unit Test App (universal windows).

Make a reference to your classe (i.e. add reference -> pick from solution your app project).

Make an UnitTest for your viewmodel class (e.g. 'MainViewModel') and test the methods and properties (e.g. concentrate at the method(s) for the command)