nerdexam
Cisco

200-901 · Question #491

Drag and Drop Question Refer to the exhibit. Drag and drop the code from the bottom onto the box where the code is missing in the Python unittest to verify whether the function returns the correct…

The correct answer is formatted_name. This question tests the ability to correctly structure a basic Python unittest to import modules, call a function, and assert its return value.

Software Development and Design

Question

Drag and Drop Question Refer to the exhibit. Drag and drop the code from the bottom onto the box where the code is missing in the Python unittest to verify whether the function returns the correct values. Not all options are used. Answer:

Exhibit

200-901 question #491 exhibit

Answer Area

Drag items

unitunittestimportexportformatted_namenameresult

Correct arrangement

  • formatted_name

Explanation

This question tests the ability to correctly structure a basic Python unittest to import modules, call a function, and assert its return value.

Approach. To complete the Python unittest correctly, the blanks should be filled as follows:

  1. First blank (import ______): Drag 'unittest' into this box. Python's standard unit testing framework is accessed via the unittest module.
  2. Second blank (from name_function ______ formatted_name): Drag 'import' into this box. This is the correct syntax to import a specific function (formatted_name) from a module (name_function).
  3. Third blank (result = ______ ("User", "Name")): Drag 'formatted_name' into this box. The result variable should store the output of calling the formatted_name function with the given arguments.
  4. Fourth blank (self.assertEqual(______, "User Name")): Drag 'result' into this box. The assertEqual method compares the actual value (stored in the result variable) with the expected value ('User Name').

This sequence correctly sets up a unit test: importing the necessary modules, calling the function under test, and then asserting that its return value matches the expected output.

Common mistakes.

  • common_mistake. The most common mistakes, as seen in the provided incorrect attempt, include:
  • Using 'export' instead of 'formatted_name' for the function call (e.g., result = export("User", "Name")). 'export' is not a standard Python keyword or function for this purpose, especially not for calling a function named formatted_name.
  • Using 'formatted_name' instead of 'result' in the assertEqual call (e.g., self.assertEqual(formatted_name, "User Name")). formatted_name refers to the function itself, not the value returned by calling the function. The assertion needs to compare the result of the function call with the expected value.
  • Other incorrect choices like 'unit' or 'name' are not appropriate module names, keywords, or variables for the given context.

Concept tested. Python unit testing fundamentals, including importing modules (unittest and custom functions), calling functions, and using assertion methods (assertEqual) within a unittest.TestCase class.

Reference. null

Topics

#Python Programming#Unit Testing#Test Automation#Software Testing

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice