Last updated on - October 21st, 2018
One question that may come to your mind is why do we need to create a project to automate the application. Let’s understand the need for the project by the reverse engineering approach. After that, we will explore how to create a project in Eclipse.
To have automated software testing in place, you need to write an automation code. To write an automation code, you need a class in the Java world. A class can only be created within a package, which is present inside the Java project.
You need to create a project in your favorite integrated development environment (IDE) like Eclipse. The project provides you a structured way to manage all your code files and resources.
Let’s understand Java project structure in Eclipse using the image below.
In this article, I will explain step by step details how to create a Java project in Eclipse.
The whole process is very simple and straightforward. I will segregate it into four different parts.
1) Download and Launch Eclipse
2) Create a New Project
3) Create a New Package in the Project
4) Create a New Class Inside the Package
Download and Launch Eclipse
1). Download the latest Eclipse from Eclipse download link and start Eclipse IDE just by double click on eclipse icon (eclipse.exe on Windows OS).
2). Provide workspace folder name when asked while launching the Eclipse.
Workspace is nothing but the dedicated folder in your system (of your choice), where you will place your projects and automation artifacts. On selecting a workspace, Eclipse would recognize all the projects present in the workspace folder.
3). Once Eclipse is launched, you will see a welcome page.
Welcome page contains many useful links which you can refer to learn. For now, you can close this page and move ahead to create a project.
To make it easy for you, I have created a video tutorial on how to create a project in Eclipse with structure layered diagram, that you can watch below to understand it practically.
However, if you just want to follow the text-instructions, then you can follow our step by step tutorial on how to create a project in Eclipse.
Create a New Project
1). To create a new project, navigate to File > New > Project.
2). This will open a new dialog where you can select the type of the project you want to create like Java Project, Maven Project etc.
Let’s select ‘Java Project’ as a part of this exercise and click on ‘Next’ button.
3). Provide your project name ‘JavaProjectDemo’, select ‘execution environment (JRE)’ version and click on ‘Finish‘ button.
You can change the JRE version as per your choice. Do not change it if you want to continue with the latest Java version installed on your system.
4). Java project is created now and listed in ‘Package Explorer‘ in Eclipse.
Create a New Package
As per the Java standard project structure, you should create a package inside your project to segregate different types of files or resources.
If you will not create package explicitly, then eclipse will create a new package with default name automatically. However, it’s always good to create a package and provide an appropriate name.
Let’s understand how to create a package.
1). Right click on ‘src’ folder and select New > Package
2). Give package name ‘testCases‘ and click on ‘Finish‘.
3). You can see a new package under the ‘src’ folder as shown below.
Create a New Class
To write Java code, you need to create a class inside the package. Let’s see step by step details to create a new class in eclipse.
1). Right-click on a package that you have created in the previous section and select New > Class
2). Give class name ‘DemoTest‘, select option ‘public static void main‘ option and click on ‘Finish‘.
If you want to run pure Java code, you need to select ‘public static void main’ option.
However, to run the Selenium WebDriver programs you don’t need the main program. So, select accordingly.
3). Now, your project structure looks like as shown below
Points to Note
Similar to the above steps, you can create as many packages and classes you want as per your requirement to categorize different test artifacts.
Now, your project is ready to run Java programs, as Java libraries (Jars) are by-default associated with your project in Eclipse under ‘JRE System Library [JavaSE-1.8]‘.
Next, you can configure Selenium WebDriver libraries to this project to enable the use of Selenium WebDriver APIs and start automating your application.
Also, you can enhance the same project towards creating a test automation framework.
I hope this article helped you to understand how to create a project in Eclipse. Further, you can also read other related articles.
Let me know if you have any questions. Share your thoughts in the comment section.
Do you know someone who can benefit from the information in the article? Share it with them on Facebook, LinkedIn, Twitter or Google Plus.
For Further Reading :
- How to Learn Automation Testing Easily
- How Automated Testing Tools Work
- What is Selenium
- Top 10 Benefits of Automation Testing