- In Eclipse, go to File -> New -> Other...
- Now Select Maven -> Maven Project
- Click Next,
- Select "Create a simple project (Skip archetype selection)", Next
- Enter Group Id and Artifact Id and click Finish.
- Now open the pom.xml and add the following dependency for Junit 4 under dependencies,
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <scope>test</scope> </dependency> </dependencies>
- Create a java file,
package myprog; public class Addition { public int add (int no1, int no2) { return no1 + no2; } }
- Now write a text class for the class we created under src/test/java package,
package myprog; import static org.junit.Assert.assertEquals; import org.junit.Test; public class AdditionTest { @Test public void addTwoNumbers() { Addition addition = new Addition(); assertEquals(5, addition.add(2, 3)); } }
Now let's run the maven test command to run the test cases, simply right click on your project folder and select Run As -> Maven test
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Java,
- Deep Dive into Java 8 Predicate Interface
- Read and Parse XML file using Java DOM Parser [Java Tutorial]
- Java 8 Predicate Functional Interface isEqual() Method Example
- Convert Multidimensional Array toString In Java
- How to read int value using Scanner Class Java
- Spring Boot AI + LLM + Java Code Example
- Write to a File using Java Stream API
- Implementing Bubble Sort Algorithm using Java Program
- How to Fix XmlBeanDefinitionStoreException in Java SpringBoot ApplicationConfig.xml
- YAML Parser using Java Jackson Library Example
- [Fix] java: integer number too large compilation error
- Convert JSON String to Java GSON Object Example
- Read a file using Java 8 Stream
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Pretty Print JSON String in Java Console Output
- Java JDBC with Join Queries Example
- How to Check For Updates on Windows 11 (Step-by-Step)
- [Fix] java.net.MalformedURLException: unknown protocol
- How to display date and time in GMT Timezone in Java
- Error: LinkageError occurred while loading main class UnsupportedClassVersionError [Eclipse Java]
- How to convert a String to Java 8 Stream of Char?
- RabbitMQ Queue Listener Java Spring Boot Code Example
- 5+ Fibonacci number Series Java Program Examples [ 0 1 1 2 3 ..]
- Handling NullPointerException with Java Predicate
More Posts:
- Iterate over an Array using Java 8 Stream and foreach - Java
- How to add Widgets to MacBook Desktop - HowTos
- cURL DELETE Request with Examples - cURL
- Open Docker Desktop from macOS Terminal - Docker
- Android-Failed to install apk on device EOF Timeout Error - Android
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ - Java
- Python: Convert int to binary String - Python
- How to set an emoji as Zsh terminal prompt in macOS - MacOS