Testing Jedis API Using Junit Test Case in Eclipse IDE
In this article, we will learn how to set up a Junit testing environment for testing Jedis API, which will interact with the Redis database.
Join the DZone community and get the full member experience.Join For Free
- Eclipse (any version) with Maven capabilities
- Java 8+
- Redis and Jedis
Installing Redis Server on Windows
- Click on the link: https://github.com/dmajkic/redis/downloads
- Download redis-2.4.5-win32-win64.zip file
- Unzip the file and go to the 64bit folder. There you can find redis-server.exe
- To start the Redis server, execute the redis-server.exe file.
Installing Eclipse-IDE on Windows
2. Download eclipse-inst-jre-win64.exe file and run the eclipse installer.
3.Select Eclipse IDE for Eclipse committers and install
Creating Maven Project in Eclipse IDE
1.Open the Eclipse IDE
2.Go to File > New > Project
3.Go to Maven -> Maven Project and click Next.
4.Select your workspace location and click Next
5.Select quick start maven archetype and click Next.
6.Enter Group Id, Artifact Id, and package name.
- Group Id: Fill a groupId for the project of your choice.
- Artifact Id: Fill artifactId for the project of your choice.
- Package: java package structure of your choice
7.The above process will create a project structure like below.
8.Place the HostPort.java file in com.example.demo package.
9.Add the WelcomeTest.java file in com.example.demo package.
10. Replace the pom.xml with the below content.
Running the Junit Test Case
- Build the Maven project and run the test case as shown below.
2.Check the test result.
Cross Verifying the Result From Redis Client
- To start the Redis client, execute the redis-cli.exe file
- Type get welcome on the console, I will give world
So, we are able to test the Jedis API using Junit.
Further, this test case can be customized according to your needs.
Feel free to ask questions.
Opinions expressed by DZone contributors are their own.