In this series, I will develop a chat bot by using Microsoft Bot Framework and Graph API with VSTS to enable DevOps.
Unit Tests for Bot Framework
Testing is one of the key concept to make DevOps successful, but unit testing of Bot Framework is different from other projects such as MVC. The article below explain the concept very well, so I won’t duplicate the effort to explain it here.
Unit Testing for Bot Applications
https://www.microsoft.com/reallifecode/2017/01/20/unit-testing-for-bot-applications/
Thanks to Catalyst team and Mor Shemesh who shared their precious knowledge and allow me to re-use your contents.
Development Environment
VSTS project
VSTS (Visual Studio Team Services) is Microsoft tool which I use for this project. If you don’t have VSTS account, signup the trial.
1. Create new project in VSTS.
2. I specified Git as version control and Agile for template.
3. Once project setup, click [Clone in Visual Studio]
4. Map to local folder.
Visual Studio Project
1. Create new solution in Team Explorer
2. Select Bot Application template. I name the project as O365 Bot.
3. Add Unit Test Project, too. I name it as O365Bot.UnitTests.
Create unit test helper
BotBuilder github has great resource for unit testing.
1. Download source code from BotBuilder GitHub (https://github.com/Microsoft/BotBuilder)
2. Add a Helper folder in the Unit Test project.
3. Copy below files into the helper folder.
– BotBuilder-masterCSharpTestsMicrosoft.Bot.Builder.TestsConversationTest.cs
– BotBuilder-masterCSharpTestsMicrosoft.Bot.Builder.TestsDialogTestBase.cs
– BotBuilder-masterCSharpTestsMicrosoft.Bot.Builder.TestsFiberTests.cs
As these files also include test class, delete followings.
– ConversationTest class in ConversationTest.cs
– FiberTests class in FiberTest.cs
4. Add following NuGet packages and apply latest versions for both bot and unit test projects.
– BotBuilder
– Moq
* I didn’t update MSTest packages as the latest version didn’t work well. The version I use is 1.1.11
5. Add System.Web reference and O365Bot project reference.
6. Build the solution once.
Add unit test and execute
All the prerequisites are ready. Let’s add test.
1. Replace the code in UnitTest1.cs with following.
2.Build the solution.
3. Run the test from Text Explore.
Summery
I will add AuthBot to enable ADAL authentication for Office 365 in the next article. Don’t forget to Check-in the code to VSTS.
The code is hosted at my GitHub
Ken
This post first appeared on MSDN Blogs | Get The Latest Information, Insights, Announcements, And News From Microsoft Experts And Developers In The MSDN Blogs., please read the originial post: here