- Basics about test projects
- Mocking dependencies using Fakes
- Hosting Web API in tests using OWIN
- Creating an automated Web Test
-
Discussion points:
- Describe why test automation is very important for short iteration times and continuous delivery
- Discuss different types of automated tests (e.g. unit tests, integration tests, automated UI tests, etc.)
- Discuss the importance of fast tests (e.g. less costs for hosted build controllers, fast tests are executed more often, less waiting time for dev teams, etc.) and how mocking of backend services can help to achieve that
-
Remove generated
UnitTest1.cs
. -
Switch to latest version of .NET (4.6.1) in the Books.Test project properties page just like you did for the Books project in exercise 1
-
Add a reference to the Web API project from your new test project.
-
Add references to the following framework assemblies:
System.ComponentModel.Composition
System.ComponentModel.Composition.Registration
System.Reflection.Context
-
Install necessary NuGet packages by running the following commands in Visual Studio's Package Manager Console (you can use Manage NuGet Packages for Solution instead if you prefer GUI over PowerShell):
Install-Package Microsoft.AspNet.WebApi.Owin -Project Books.Test
Install-Package Microsoft.Owin.Host.SystemWeb -Project Books.Test
Install-Package Microsoft.AspNet.WebApi.OwinSelfHost -Project Books.Test
-
Discussion points:
- Describe the concept of mocking
- Short introduction to Microsoft Fakes (shims vs. stubs)
-
Replace
Fakes/Books.fakes
with the following code:<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/"> <Assembly Name="Books"/> <StubGeneration> <Clear/> <Add TypeName="INameGenerator"/> </StubGeneration> <ShimGeneration> <Clear/> </ShimGeneration> </Fakes>
-
Copy
.cs
files from Assets/Exercise-3-Tests into your test project. Make yourself familiar with the two test files. -
Discussion points:
- Short introduction into unit testing with Visual Studio
- Describe how OWIN is used to host a web server in an integration test (
IntegrationTest.cs
)
-
Build your test project. There should not be errors.
-
Discussion points:
- Describe different type of web testing (e.g. API testing, end-to-end testing)
- Mention and describe other important web test tools (e.g. Protractor for AngularJS, Selenium for browser automation) and their integration in Visual Studio (e.g. blog article Getting Started with Selenium Testing in a Continuous Integration Pipeline with Visual Studio)
- Short introduction to Visual Studio Web Tests
-
Discussion points:
- Describe other capabilities of Visual Studio Web Tests (e.g. loops, conditions, data-driven tests, parameters)
-
Open the request's properties and change the URL appropriately.
-
Discussion points:
- Describe other request properties offered by Visual Studio
-
Parameterize web server. This is important if you have lots of requests. With parameters, tests become much easier to maintain.
-
Make yourself familiar with the web test after server parameterization.
-
Discussion points:
- Describe other request properties offered by Visual Studio
- Describe validation rules
-
Start an instance of your OWIN web server (press Ctrl+F5 to start it without debugger).
-
Discussion points:
- Discuss the importance of load testing
- General overview over Visual Studio load testing capabilities
-
Select the following test settings (select default values for settings not mentioned here):
- Select On-premise Load Test (we will move to the cloud later)
- 100 test iterations
- 5 seconds sampling rate
- Constant load of 10 users
- Add the
GetBooksTest
to the load test
-
Discussion points:
- Describe other capabilities of Visual Studio load testing
If you have time left, you could additionally cover topics like:
- Create custom validation rule
- Use web UI from final sample code to demo HTML-related web test features
- (Not recommended but possible if you have a very web-development-oriented audience) Add a Jasmine unit test for Angular client