</>

Technology

Rest Assured

Difficulty

Beginner

Interview Question

How to fix the error: import io.restassured.RestAssured cannot be resolved?

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

  1. Save pom.xml
  2. Right-click project → Maven → Reload project
  3. Or run: mvn clean install
  4. The import should resolve correctly

Summary

ScenarioFix
Class in src/main/javaRemove <scope>test</scope>
Class should be in testMove to src/test/java
Dependency missing entirelyAdd Rest Assured to pom.xml

Follow AutomateQA

Related Topics