Answer
Fix: import io.restassured.RestAssured cannot be resolved
This error typically occurs when the scope of the Rest Assured dependency is set to test, which limits access to the classes from within source code (only accessible in the test sources).
Root Cause
When you add the dependency with scope: test:
XML
<!-- WRONG - causes import error in main source -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.3.0</version>
<scope>test</scope> ← This limits access to test sources only
</dependency>
Solutions
Solution 1: Remove the scope attribute
XML
<!-- CORRECT - accessible from all source directories -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.3.0</version>
<!-- No scope = compile scope = accessible everywhere -->
</dependency>
Solution 2: Move your class to test sources
If the scope: test is intentional, move your API test class to:
CODE
src/test/java/<package>
Not in src/main/java/<package>.
Solution 3: Full Dependency Block
XML
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>5.3.0</version>
</dependency>
After Fixing
- ✓Save
pom.xml - ✓Right-click project → Maven → Reload project
- ✓Or run:
mvn clean install - ✓The import should resolve correctly
Summary
| Scenario | Fix |
|---|---|
Class in src/main/java | Remove <scope>test</scope> |
| Class should be in test | Move to src/test/java |
| Dependency missing entirely | Add Rest Assured to pom.xml |
