Monitoring your CI/CD daily can sometimes be a very cumbersome job. Learn how you can make your life easier by posting your Test Studio results directly in Slack.
When it comes to testing, if your organization is using many different tools in its build chain, you probably need to monitor several different UIs. That could be simplified though, if most of your monitoring could be done in one place. If, by chance, your team uses Slack for collaboration, you can use it for more than just messaging. Slack has great extensibility through its APIs.
Telerik Test Studio allows for easy integrations with other tools and solutions, thanks to its execution extensions. In this blog post I will show you how easily you can build an extension that will post your test list run results in Slack.
One good security practice is to keep secrets out of the source code and to do that we will proceed with creating a new registry entry that will hold our web hook URL.
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node
(if you are using 32-bit Windows use HKEY_LOCAL_MACHINE\SOFTWARE
instead)Now let's get your hands dirty and start building our Test Studio extension.
Our next step should be adding dependencies to the project. There are two dependencies that we need to refer to.
The First one is Newtonsoft.Json. You can add it as nuget library from the Visual Studio NuGet manager, just make sure to install version 10.0.3.
The second dependency is ArtOfTest.WebAii.Design.DLL. To add it, just right click on project references and select "Add reference...". Select "Browse" and navigate to your Test Studio bin folder (by default it is located in %ProgramFiles%\Progress\Test Studio\Bin)
After adding the necessary dependencies, we are ready to start coding our extension. Let's begin with the implementation of the Test Studio run time extension interface. To do that, add a new class file to the project and name it SlackBot.cs. This class should implement the IExecutionExtension
interface.
The resulting file should look like this:
Method OnBeforeTestListStarted
is called every time before the start of test list execution, and that's the right place for us to read our registry key, which we created earlier in this post.
In OnAfterTestListCompleted
, we receive the test list execution result when the run completes. Here we are creating and sending the Slack message.
Now we need to create data classes, needed for serialization/de-serialization. Create a folder in the project and give it a name "Data." In it add one new file named "Message.cs":
Every Slack message can have zero or more attachments and each of those attachments can have zero or more fields.
Create one more class file in the "Data" folder and name it MessageCreator.cs
. We will use it to create different messages, depending on the result. Slack allows a great level of message customization. You can learn more about the Slack message format here.
Our messages will have one attachment with two fields in it - the first field will contain the test list name and the second one the run result:
As a final step we need to create the SlackClient class. In its constructor we will set the web hook URL. We will add one more method to the class - PostMessage
, which as its name suggests, will post messages to Slack:
Our final project structure should looks like this:
Now we can build our project. In Visual Studio, right click on the project and select "Build." When the build completes, copy SlackBot.dll and paste it into the Test Studio plugin folder (by default it is located in %ProgramFiles%\Progress\Test Studio\Bin\Plugins):
Now we are ready to test our extension. Start Test Studio and run one of your test lists.
And behold! Your test results are in Slack!
Now you saw how easy it can be to extend Test Studio and integrate it with other products.
If you want to try building this extension or creating your own, you can start a free, fully functional 30-day trial:
Deyan is software engineer on the Telerik Test Studio Team. As a software engineer he has experience with mobile and desktop applications.