-
Notifications
You must be signed in to change notification settings - Fork 2
03 Testing
Robert Friberg edited this page May 28, 2014
·
3 revisions
This module explores automated testing alternatives for your data models.
Notes: Uses NUnit, assumes you have a test runner available. There is an extension available for VS, also resharper supports NUnit out of the box.
- Open the Todo project in Visual Studio from the Ex01 folder
- Add a class library to the solution called
Todo.Test
- In the new library, add a nuget reference to
NUnit
- Add a reference to the Todo.Core project
- Rename the Class1 to TodoTests and add TestFixture attribute.
- Create a test by adding the following method:
[Test] public void Todo_Constructor_args_are_picked_up() { const int expectedId = 42; const string expectedTodo = "Give the dog a dose of meth"; var todo = new Core.Todo(expectedId, expectedTodo); Assert.AreEqual(expectedId, todo.Id); Assert.AreEqual(expectedTodo, todo.Title); }
- Execute the test
You're on your own now, create tests for the following:
-
That TodoModel.SetCategory(int,category) creates a category when missing
-
That SetCompletedCommand has the desired effect
-
Create a general smoke test which creates an engine, executes some commands and queries. Tip: You can create an engine for isolated test and in-memory storage using the following syntax:
var config = new EngineConfiguration().ForIsolatedTest(); var engine = Engine.LoadOrCreate<TodoModel>(config);