I assume you have done a little unit testing of C# classes, some time ago ...
This exercise is supposed to refresh you knowledge on unit testing and add to this knowledge.
Before starting this part of the exercise: Please write down the starting time.
What is the time now? How much time did you spend on this exercise?
Before starting this part of the exercise: Please write down the starting time.
What is the time now? How much time did you spend on this exercise?
Before starting this part of the exercise: Please write down the starting time.
Add two equals() methods to the Student class. Make sure the Student class implements the interface IEquatable<T>. An example.
A two test methods to StudentTest to test the two equals() methods
What is the time now? How much time did you spend on this exercise?
Visual Studio has a feature to check which lines has be executed by you test.
Read the article Using Code Coverage to Determine How Much Code is being Tested and try it on your project.
Keep on adding new test cases to you test until you have a perfect cover i.e. all lines of you class has been executed by the test.
Having a perfect cover is nice, but it does not guarantee that you program is correct!
Before starting this part of the exercise: Please write down the starting time.
The Student class should have a few class invariants
These invariants must be inforced in the properties (set) and the constructor in the Student class:
if (age < 0) { throw new ArgumentException("age");
}What is the time now? How much time did you spend on this exercise?
Before starting this part of the exercise: Please write down the starting time.
Now you must add to the tests, to check that exceptions are thrown as expected.
Use the idiom
try { obj.SomeExceptionThrowingMethod(); Assert.Fail(); } catch (SomeException ex) { Assert.AreEquals("some message", ex.Message); }
You should also try to the [ExpectedException(typeof(ArgumentException))]
annotation
What is the time now? How much time did you spend on this exercise?