← Back to libraryQuestion 243 of 468
🔌REST AssuredBeginner

Base URI, Base Path, and Port

📌 Definition:

RestAssured.baseURI, basePath, and port set the common server target once so individual tests use short relative paths (.get('/users')) instead of full URLs, making the suite portable across environments.

📖 Detailed Explanation:

Setting RestAssured.baseURI = 'https://api.example.com'; RestAssured.basePath = '/v1'; RestAssured.port = 443; means .get('/users') hits https://api.example.com:443/v1/users. This is typically done in a @BeforeClass/@BeforeSuite so every test inherits it, and you can override per test via given().baseUri(...). Externalizing these values (from a properties file or env variable) lets the SAME tests run against dev/staging/prod by changing config, not code. Resetting with RestAssured.reset() clears static config between suites to avoid leakage.

🔑 Key Points:
  • baseURI/basePath/port set the target once → relative paths in tests
  • Set in @BeforeClass/@BeforeSuite; override per-request with baseUri()
  • Externalize to config → run same tests on any environment
  • RestAssured.reset() clears static config between suites
🌍 Real-World Example:

@BeforeClass sets RestAssured.baseURI from a config file, so switching from staging to prod is a one-line property change and every test retargets automatically.

🎯 Scenario-Based Interview Question:

How do you run the exact same REST Assured suite against staging and production without editing the tests?