Setting Up System: Eclipse, Java, Maven, Rest-assured and TestNG
What You Need Installed
- JDK (Java Development Kit): provides the compiler and runtime needed to write and run Java code.
- Eclipse IDE: the editor used to write, run, and debug Java and Rest Assured projects.
- Maven: a build tool that manages project dependencies (like Rest Assured and TestNG) automatically.
- Rest Assured & TestNG: added as Maven dependencies inside the project's
pom.xmlrather than installed separately.
Basic Setup Steps
Install the JDK and set the JAVA_HOME environment variable, install Eclipse (with the Maven plugin, usually bundled by default), create a new Maven project, and add the Rest Assured and TestNG dependencies to pom.xml.
Why This Foundation Matters
Getting this environment right once means every later exercise — writing Java code, running TestNG tests, or automating APIs with Rest Assured — works smoothly without setup issues getting in the way.
Step-by-Step Installation Check
After installing each piece, confirm it works from a terminal. Catching a problem here saves hours of confusing errors later inside the IDE.
java -version # should show the JDK you installed
javac -version # proves it is a full JDK, not only a runtime
mvn -v # shows Maven version and the Java home it uses
echo %JAVA_HOME% # Windows; use echo $JAVA_HOME on macOS or Linux
If mvn -v reports a different Java than java -version, fix JAVA_HOME first. On Windows, also add %JAVA_HOME%in and the Maven bin folder to the Path variable, then open a new terminal so the change is picked up. Eclipse ships with its own embedded Maven, so a separate Maven install is mainly needed for running builds from the command line or a CI server.
Creating the Project and pom.xml
- In Eclipse, choose File > New > Maven Project, tick "Create a simple project", and give a Group Id such as
com.exampleand an Artifact Id such asapi-tests. - Open
pom.xmland add the dependencies below. Look up the current versions on Maven Central and place them in the properties section. - Right-click the project and select Maven > Update Project so Eclipse downloads the libraries.
<properties>
<maven.compiler.release>17</maven.compiler.release>
<restassured.version>REPLACE_WITH_CURRENT</restassured.version>
<testng.version>REPLACE_WITH_CURRENT</testng.version>
</properties>
<dependencies>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${restassured.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Set maven.compiler.release to the JDK version you actually installed.
Keeping versions in properties means you update them in one place later. Avoid copying very old version numbers from random blog posts; outdated libraries are a common cause of strange errors and security warnings.
A sensible folder layout keeps things tidy as the project grows: page or endpoint helpers under src/test/java/api, test classes under src/test/java/tests, and configuration files such as base URLs under src/test/resources.
Your First Test to Prove the Setup
Create a class under src/test/java. Test code belongs there because the dependencies use the test scope.
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import org.testng.annotations.Test;
public class SmokeTest {
@Test
public void getSinglePost() {
given()
.baseUri("https://jsonplaceholder.typicode.com")
.when()
.get("/posts/1")
.then()
.statusCode(200)
.body("id", equalTo(1));
}
}
Install the TestNG plugin from the Eclipse Marketplace to get the "Run As > TestNG Test" option, or run mvn test from the project folder.
Problems New Learners Hit
- "No compiler is provided": Eclipse points to a JRE. Add the JDK under Window > Preferences > Java > Installed JREs.
- Red imports for Rest Assured: the test class sits in
src/main/java, where test-scoped libraries are not visible. - Dependencies not downloading: a company proxy blocks Maven; configure it in
settings.xml. - Static import errors:
given()and matchers need the static imports shown above. - TestNG tests not found by
mvn test: class names should end withTest, or you should point the Surefire plugin at atestng.xmlfile.
Ready to master real-world software testing?
Learn manual and automation testing hands-on with mentor-led sessions.