You can use the built-in test feature to uncover bugs and prevent regressions. A test execution verifies that agent responses have not changed for end-user inputs defined in the test case.
To get more information about TestCase, see:
resource "google_dialogflow_cx_agent" "agent" {
display_name = "dialogflowcx-agent"
location = "global"
default_language_code = "en"
supported_language_codes = ["fr", "de", "es"]
time_zone = "America/New_York"
description = "Example description."
avatar_uri = "https://storage.cloud.google.com/dialogflow-test-host-image/cloud-logo.png"
enable_stackdriver_logging = true
enable_spell_correction = true
speech_to_text_settings {
enable_speech_adaptation = true
}
}
resource "google_dialogflow_cx_page" "page" {
parent = google_dialogflow_cx_agent.agent.start_flow
display_name = "MyPage"
transition_routes {
intent = google_dialogflow_cx_intent.intent.id
trigger_fulfillment {
messages {
text {
text = ["Training phrase response"]
}
}
}
}
event_handlers {
event = "some-event"
trigger_fulfillment {
messages {
text {
text = ["Handling some event"]
}
}
}
}
}
resource "google_dialogflow_cx_intent" "intent" {
parent = google_dialogflow_cx_agent.agent.id
display_name = "MyIntent"
priority = 1
training_phrases {
parts {
text = "training phrase"
}
repeat_count = 1
}
}
resource "google_dialogflow_cx_test_case" "basic_test_case" {
parent = google_dialogflow_cx_agent.agent.id
display_name = "MyTestCase"
tags = ["#tag1"]
notes = "demonstrates a simple training phrase response"
test_config {
tracking_parameters = ["some_param"]
page = google_dialogflow_cx_page.page.id
}
test_case_conversation_turns {
user_input {
input {
language_code = "en"
text {
text = "training phrase"
}
}
injected_parameters = jsonencode({ some_param = "1" })
is_webhook_enabled = true
enable_sentiment_analysis = true
}
virtual_agent_output {
session_parameters = jsonencode({ some_param = "1" })
triggered_intent {
name = google_dialogflow_cx_intent.intent.id
}
current_page {
name = google_dialogflow_cx_page.page.id
}
text_responses {
text = ["Training phrase response"]
}
}
}
test_case_conversation_turns {
user_input {
input {
event {
event = "some-event"
}
}
}
virtual_agent_output {
current_page {
name = google_dialogflow_cx_page.page.id
}
text_responses {
text = ["Handling some event"]
}
}
}
test_case_conversation_turns {
user_input {
input {
dtmf {
digits = "12"
finish_digit = "3"
}
}
}
virtual_agent_output {
text_responses {
text = ["I didn't get that. Can you say it again?"]
}
}
}
}
The following arguments are supported:
display_name
-
(Required)
The human-readable name of the test case, unique within the agent. Limit of 200 characters.tags
-
(Optional)
Tags are short descriptions that users may apply to test cases for organizational and filtering purposes.
Each tag should start with "#" and has a limit of 30 characters
notes
-
(Optional)
Additional freeform notes about the test case. Limit of 400 characters.
test_config
-
(Optional)
Config for the test case.
Structure is documented below.
test_case_conversation_turns
-
(Optional)
The conversation turns uttered when the test case was created, in chronological order. These include the canonical set of agent utterances that should occur when the agent is working properly.
Structure is documented below.
parent
-
(Optional)
The agent to create the test case for.
Format: projects/
The test_config
block supports:
tracking_parameters
-
(Optional)
Session parameters to be compared when calculating differences.
flow
-
(Optional)
Flow name to start the test case with.
Format: projects/
page
-
(Optional)
The page to start the test case with.
Format: projects/
The test_case_conversation_turns
block supports:
user_input
-
(Optional)
The user input.
Structure is documented below.
virtual_agent_output
-
(Optional)
The virtual agent output.
Structure is documented below.
The user_input
block supports:
input
-
(Optional)
User input. Supports text input, event input, dtmf input in the test case.
Structure is documented below.
injected_parameters
-
(Optional)
Parameters that need to be injected into the conversation during intent detection.
is_webhook_enabled
-
(Optional)
If webhooks should be allowed to trigger in response to the user utterance. Often if parameters are injected, webhooks should not be enabled.
enable_sentiment_analysis
-
(Optional)
Whether sentiment analysis is enabled.
language_code
-
(Optional)
The language of the input. See Language Support for a list of the currently supported language codes.
Note that queries in the same session do not necessarily need to specify the same language.
text
-
(Optional)
The natural language text to be processed.
Structure is documented below.
event
-
(Optional)
The event to be triggered.
Structure is documented below.
dtmf
-
(Optional)
The DTMF event to be handled.
Structure is documented below.
text
-
(Required)
The natural language text to be processed. Text length must not exceed 256 characters.event
-
(Required)
Name of the event.digits
-
(Optional)
The dtmf digits.
finish_digit
-
(Optional)
The finish digit (if any).
The virtual_agent_output
block supports:
session_parameters
-
(Optional)
The session parameters available to the bot at this point.
triggered_intent
-
(Optional)
The Intent that triggered the response.
Structure is documented below.
current_page
-
(Optional)
The Page on which the utterance was spoken.
Structure is documented below.
text_responses
-
(Optional)
The text responses from the agent for the turn.
Structure is documented below.
The triggered_intent
block supports:
name
-
(Optional)
The unique identifier of the intent.
Format: projects/
display_name
-
(Output)
The human-readable name of the intent, unique within the agent.
The current_page
block supports:
name
-
(Optional)
The unique identifier of the page.
Format: projects/
display_name
-
(Output)
The human-readable name of the page, unique within the flow.
The text_responses
block supports:
text
-
(Optional)
A collection of text responses.In addition to the arguments listed above, the following computed attributes are exported:
id
- an identifier for the resource with format {{parent}}/testCases/{{name}}
name
-
The unique identifier of the test case.
Format: projects/
creation_time
-
When the test was created. A timestamp in RFC3339 text format.
last_test_result
-
The latest test result.
Structure is documented below.
The last_test_result
block contains:
name
-
(Optional)
The resource name for the test case result.
Format: projects/
environment
-
(Optional)
Environment where the test was run. If not set, it indicates the draft environment.
conversation_turns
-
(Optional)
The conversation turns uttered during the test case replay in chronological order.
Structure is documented below.
test_result
-
(Optional)
Whether the test case passed in the agent environment.
PASSED
, FAILED
.test_time
-
(Optional)
The time that the test was run. A timestamp in RFC3339 text format.
The conversation_turns
block supports:
user_input
-
(Optional)
The user input.
Structure is documented below.
virtual_agent_output
-
(Optional)
The virtual agent output.
Structure is documented below.
The user_input
block supports:
input
-
(Optional)
User input. Supports text input, event input, dtmf input in the test case.
Structure is documented below.
injected_parameters
-
(Optional)
Parameters that need to be injected into the conversation during intent detection.
is_webhook_enabled
-
(Optional)
If webhooks should be allowed to trigger in response to the user utterance. Often if parameters are injected, webhooks should not be enabled.
enable_sentiment_analysis
-
(Optional)
Whether sentiment analysis is enabled.
language_code
-
(Optional)
The language of the input. See Language Support for a list of the currently supported language codes.
Note that queries in the same session do not necessarily need to specify the same language.
text
-
(Optional)
The natural language text to be processed.
Structure is documented below.
event
-
(Optional)
The event to be triggered.
Structure is documented below.
dtmf
-
(Optional)
The DTMF event to be handled.
Structure is documented below.
text
-
(Required)
The natural language text to be processed. Text length must not exceed 256 characters.event
-
(Required)
Name of the event.digits
-
(Optional)
The dtmf digits.
finish_digit
-
(Optional)
The finish digit (if any).
The virtual_agent_output
block supports:
session_parameters
-
(Optional)
The session parameters available to the bot at this point.
differences
-
(Optional)
The list of differences between the original run and the replay for this output, if any.
Structure is documented below.
triggered_intent
-
(Optional)
The Intent that triggered the response.
Structure is documented below.
current_page
-
(Optional)
The Page on which the utterance was spoken.
Structure is documented below.
text_responses
-
(Optional)
The text responses from the agent for the turn.
Structure is documented below.
status
-
(Optional)
Response error from the agent in the test result. If set, other output is empty.
Structure is documented below.
The differences
block supports:
type
-
(Optional)
The type of diff.
INTENT
, PAGE
, PARAMETERS
, UTTERANCE
, FLOW
.description
-
(Optional)
A human readable description of the diff, showing the actual output vs expected output.
The triggered_intent
block supports:
name
-
(Optional)
The unique identifier of the intent.
Format: projects/
display_name
-
(Optional)
The human-readable name of the intent, unique within the agent.
The current_page
block supports:
name
-
(Optional)
The unique identifier of the page.
Format: projects/
display_name
-
(Optional)
The human-readable name of the page, unique within the flow.
The text_responses
block supports:
text
-
(Optional)
A collection of text responses.code
-
(Optional)
The status code, which should be an enum value of google.rpc.Code.
message
-
(Optional)
A developer-facing error message.
details
-
(Optional)
A JSON encoded list of messages that carry the error details.
This resource provides the following Timeouts configuration options:
create
- Default is 40 minutes.update
- Default is 40 minutes.delete
- Default is 20 minutes.TestCase can be imported using any of these accepted formats:
{{parent}}/testCases/{{name}}
In Terraform v1.5.0 and later, use an import
block to import TestCase using one of the formats above. For example:
import {
id = "{{parent}}/testCases/{{name}}"
to = google_dialogflow_cx_test_case.default
}
When using the terraform import
command, TestCase can be imported using one of the formats above. For example:
$ terraform import google_dialogflow_cx_test_case.default {{parent}}/testCases/{{name}}