Teams App Test Tool is available in the latest prerelease version of the Microsoft Teams Toolkit. Ensure that you install the latest prerelease version of the Teams Toolkit.
Teams App Test Tool (Test Tool) makes debugging bot-based apps effortless. You can chat with your bot and see its messages and Adaptive Cards as they appear in Microsoft Teams. You don’t need a Microsoft 365 developer account, tunneling, or Teams app and bot registration to use Test Tool.
The following image shows a sample app displaying an Adaptive Card with a list of commands in Test Tool. It also provides a description of the commands so that you can test your app without manually searching your code:
The following are the advantages of Test Tool:
Sandbox environment: The sandbox environment of Test Tool emulates the behavior, look, and user experience of Teams.
Tunneling: An external tunnel service isn't necessary as Test Tool runs on a local server that your bot can communicate with.
Reduce account dependencies: Microsoft 365 Developer tenant and the app uploading permissions aren't necessary to debug the bot.
Rapid inner-loop iterations: Optimizes the process of making changes to the app design and bot logic without having to redeploy the bot to the cloud.
Mock data and activities: Test Tool makes it easy to test complex scenarios such as, sending a welcome message when a new member joins the channel, using mock data and activity triggers.
Reliable: Test Tool is reliable as the bot's Adaptive Card utilizes the same rendering technology as in Teams.
Integration with existing Teams bot applications: Test Tool integrates effortlessly with existing Teams bot applications built with Bot Framework SDK.
Support for different scopes: Test Tool supports testing in personal, team, and group chat scopes.
Prerequisites
Ensure you install the following tools for building and deploying your bots in Test Tool:
JavaScript, TypeScript, or SharePoint Framework (SPFx) build environments. Use the latest version.
Understand Test Tool
Test Tool is an npm package that has a CLI command called teamsapptester. When you run teamsapptester start, it opens a web app on your local machine that emulates the Teams web client and Bot Framework service. This web app doesn't need any cloud resources as it uses mock data to simulate the contextual information of Teams.
To use a Teams bot on Test Tool, you need to provide:
Message endpoint: A bot message endpoint is the URL that links Test Tool and your bot. You can update the endpoint with the BOT_ENDPOINT environment variable or use the default value of http://localhost:3978/api/messages.
Configuration file (Optional): A configuration file informs Test Tool about your customized contextual information in Teams. The file is named .teamsapptesttool.yml in the project's root folder. If Teams can't find this file, it uses the default configuration. For more information, see customize Teams context.
Test Tool experience in Teams Toolkit
Test Tool offers a faster debug experience for bot applications when compared to the Teams client.
Run the following command to install Teams app Test Tool CLI from npm:
npm install -g @microsoft/teams-app-test-tool
Use the teamsapp command from Teams Toolkit CLI to create your first project. Start from the folder where you want to create the project folder.
teamsapp new
You can use the CLI to create a new Teams app. The CLI leads you through a series of questions. Use the arrow keys to select an option. After you make a choice, select Enter to confirm. After you enter a suitable name for your app, your project is created.
Run the following command to deploy your app and install the required dependencies and npm packages:
teamsapp deploy --env=testtool
Run the following command to start your bot app:
npm run dev:teamsapp:testtool
Run the following command in a separate terminal to launch Teams App Test Tool:
Run the following command to initiate Teams App Test Tool:
For Command Prompt:
teamsapptester.exe start
For PowerShell:
teamsapptester.exe start
If the Test Tool for C# doesn't initiate because of a port conflict, alter the Test Tool's port number in the TEAMSAPPTESTER_PORT environment variable where you run teamsapptester.exe start.
Test Tool opens the bot in a webpage.
Activity triggers
You can mock an activity in Test Tool using activity triggers. There are two types of activity triggers:
Test Tool provides predefined activity triggers to test the functionalities of your bot.
Category
Activity
Handler
Trigger Installation Update Activity
Install bot
Uninstall bot
onInstallationUpdate onInstallationUpdateAdded
onInstallationUpdate onInstallationUpdateRemove
Trigger Conversation Update Activity
Add user
Add bot
Add channel
onMembersAdded
onTeamsMembersAddedEvent
onTeamsChannelRenamedEvent
Remove user
Remove bot
Remove channel
Remove team
onMembersRemoved onTeamsMembersRemovedEvent
onMembersRemoved onTeamsMembersRemovedEvent
onTeamsChannelDeletedEvent
onTeamsTeamDeletedEvent
Rename channel
Rename team
onTeamsChannelRenamedEvent
onTeamsTeamRenamedEvent
注意
All types of activities aren't available in all scopes. For example, you can't add or remove a channel in a personal chat or a group chat.
Predefined activity triggers are available in the Mock an Activity menu in Test Tool.
To mock an Add user activity, follow these steps:
In Test Tool, go to Mock an Activity and select Add user.
A pop-up window appears to preview the activity handler.
Select Send activity.
Bot sends a response.
Custom activity triggers
You can use Custom activity to customize activity triggers such as, reactionsAdded, to fit the requirements of your bot app. Test Tool automatically populates the required properties of the activity. You can also modify the activity type and add more properties.
Select Mock an Activity > Custom activity.
Add messageReaction to customize the activity under the property type and invoke the custom activity.
Bot sends an onReactionsAdded handler in response.
Customize Teams context
The configuration file in the project's root folder allows you to customize Teams context information such as chats, teams, and users. The file provides mock data for testing Bot Framework APIs or Bot Builder SDK methods such as TeamsInfo.getTeamMembers.
Default configuration
Test Tool contains a built-in configuration file in the project's root folder.
# yaml-language-server: $schema=https://aka.ms/teams-app-test-tool-config/0.1.0/config.schema.json
# Visit https://aka.ms/teams-app-test-tool-config-guide for more details on this file.
# This configuration file customizes the Teams context information like chats, teams, and users.
# It contains mock data for testing Bot Framework APIs or Bot Builder SDK methods such as TeamsInfo.getTeamMembers().
# You can customize this file to change API response if your bot code uses these APIs.
version: "0.1.0"
tenantId: 00000000-0000-0000-0000-0000000000001
bot:
id: 00000000-0000-0000-0000-00000000000011
name: Test Bot
currentUser:
id: user-id-0
name: Alex Wilber
userPrincipleName: alexw@example.com
aadObjectId: 00000000-0000-0000-0000-0000000000020
givenName: Alex
surname: Wilber
email: alexw@example.com
users:
- id: user-id-1
name: Megan Bowen
userPrincipleName: meganb@example.com
aadObjectId: 00000000-0000-0000-0000-0000000000021
givenName: Megan
surname: Bowen
email: meganb@example.com
- id: user-id-2
name: Adele Vance
userPrincipleName: adelev@example.com
aadObjectId: 00000000-0000-0000-0000-0000000000022
givenName: Adele
surname: Vance
email: adelev@example.com
- id: user-id-3
name: Isaiah Langer
userPrincipleName: isaiah@example.com
aadObjectId: 00000000-0000-0000-0000-0000000000023
givenName: Isaiah
surname: Langer
email: isaiahl@example.com
- id: user-id-4
name: Patti Fernandez
userPrincipleName: pattif@example.com
aadObjectId: 00000000-0000-0000-0000-0000000000024
givenName: Patti
surname: Fernandez
email: pattif@example.com
- id: user-id-5
name: Lynne Robbins
userPrincipleName: lynner@example.com
aadObjectId: 00000000-0000-0000-0000-0000000000025
givenName: Lynne
surname: Robbins
email: lynner@example.com
personalChat:
id: personal-chat-id
groupChat:
id: group-chat-id
name: Group Chat
team:
id: team-id
name: My Team
aadGroupId: 00000000-0000-0000-0000-000000000031
channels:
- id: channel-announcements-id
name: Announcements
Update the configuration file
If your bot code uses Bot Framework APIs, you can modify the configuration file to alter the API response. Let us consider an Azure DevOps notification bot installed in a team that fetches inactive bugs from Azure DevOps. It identifies the owners of the inactive bug, fetches their email addresses, and sends notifications to their personal chats on a daily basis.
To comprehensively test this bot in Test Tool, it's crucial to update the configuration file to use the correct email addresses of the owners of the inactive bugs.
Go to the .teamsapptesttool.yml file in the project's root folder.
Go to the users section and update the name, userPrincipleName, and email of the required user.
Save the file and select F5 to debug in Test Tool.
注意
When you edit the configuration file in Visual Studio Code, Intellisense automatically updates the property names and warns you if you enter invalid values.
It's vital to recognize that updating the configuration file has three major impacts:
It influences the responses obtained from Bot Framework Connector APIs, for example, TeamsInfo.getPagedMembers().
It shapes the details in the activity payload, for example, activity.recipient.
It impacts the user interface in Test Tool, for example, group chat names.
Limitations
Bot features enabled through the Teams app manifest aren't available as Test Tool doesn't process it.
Test Tool doesn't support all types of cards except Adaptive Cards.
Test Tool doesn't support the following Adaptive Card features:
Under EXPLORER, create a .localConfigs.testtool file and add the following code:
// .localConfigs.testTool
# A gitignored place holder file for local runtime configurations when debug in test tool
BOT_ID=
BOT_PASSWORD=
TEAMSFX_NOTIFICATION_STORE_FILENAME=.notification.testtoolstore.json
Go to EXPLORER > env.
Create a .env.testtool file and add the following code:
// .env.testtool
# This file includes environment variables that can be committed to git. It's gitignored by default because it represents your local development environment
# Built-in environment variables
TEAMSFX_ENV=testtool
# Environment variables used by test tool
TEAMSAPPTESTER_PORT=56150
If you have custom environment variables, set their values in .env.testtool or .env.testtool.user.
Add either an OpenAI key or Azure OpenAI key and endpoint in .env.testtool.user.
From the left pane, select Run and Debug (Ctrl+Shift+D) and select Debug in Test Tool in dropdown list.
Test Tool successfully debugs your existing bot.
FAQ
How can I test my bot if Test Tool doesn't support its features?
You can always use the Teams client to test the features that Test Tool doesn't support. Select the option Debug in Teams (Edge) or Debug in Teams (Chrome) to test your application in the Teams client.
How would I know if Test Tool doesn't support features in my bot?
Test Tool shows a warning message in conversation and log panel when it detects unsupported features.
Does Microsoft recommend using only Test Tool for testing bot applications?
No. We always recommend users to test their bot application in the Teams client before moving the application to the production environment.
Teams 工具組是 Visual Studio Code 和 Visual Studio 2022 的延伸模組。 它可協助開發人員使用整合式身分識別、雲端記憶體和其他服務,跨 Microsoft 365 和 Azure 來建立和部署 Teams 應用程式。 在此學習路徑中,您將瞭解如何使用適用於 Visual Studio Code 的 Teams 工具組來建置 Microsoft Teams 應用程式。