Bird
0
0

Identify the error in this Locust test code:

medium📝 Debug Q14 of 15
Rest API - API Testing and Monitoring
Identify the error in this Locust test code:
from locust import HttpUser, task

class MyUser(HttpUser):
    def index(self):
        self.client.get("/")
AClass name should be lowercase
BHttpUser class should be imported from requests
Cself.client.get should be self.get
DMissing @task decorator before index method
Step-by-Step Solution
Solution:
  1. Step 1: Check for task decorator usage

    Locust requires the @task decorator on methods to mark them as tasks to run.
  2. Step 2: Verify other parts of the code

    HttpUser is correctly imported, self.client.get is correct, and class names are capitalized by convention.
  3. Final Answer:

    Missing @task decorator before index method -> Option D
  4. Quick Check:

    Tasks need @task decorator [OK]
Quick Trick: Always add @task decorator to methods to run as tasks [OK]
Common Mistakes:
MISTAKES
  • Forgetting @task decorator
  • Importing HttpUser from wrong module
  • Using self.get instead of self.client.get

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes