0% found this document useful (0 votes)
3 views4 pages

Lecture 6 Testing JUnitConfiguration

This document provides a comprehensive step-by-step guide for setting up Eclipse 2024-12 with JDK 25 and JUnit 5. It includes instructions for downloading Eclipse, adding JDK, creating a Java project, adding JUnit 5 library, and creating test classes. Additionally, it covers running tests and optional settings for default JDK configuration.

Uploaded by

Khin Myat Thu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Lecture 6 Testing JUnitConfiguration

This document provides a comprehensive step-by-step guide for setting up Eclipse 2024-12 with JDK 25 and JUnit 5. It includes instructions for downloading Eclipse, adding JDK, creating a Java project, adding JUnit 5 library, and creating test classes. Additionally, it covers running tests and optional settings for default JDK configuration.

Uploaded by

Khin Myat Thu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Full Step-By-Step Setup for Eclipse 2024-12 + JDK 25 + Junit 5

Step 1 — Download & Extract Eclipse


2024-12 (ZIP version)
1. Go to Eclipse Downloads
2. Choose Eclipse IDE for Java Developers → 2024-12 → Download ZIP
3. Extract the ZIP to a folder, for example:
4. C:\Eclipse2024-12
5. Run [Link] (Windows) or eclipse (macOS/Linux)

✅ Using the ZIP avoids installer Oomph / XML parsing issues.

Step 2 — Add JDK 25 to Eclipse


1. Open Eclipse → Window → Preferences
2. Navigate to Java → Installed JREs
3. Click Add… → Standard VM → Next
4. Click Directory… and browse to your JDK 25 folder:
o Windows: C:\Program Files\Java\jdk-25
o macOS: /Library/Java/JavaVirtualMachines/[Link]/Contents/Home
o Linux: /usr/lib/jvm/jdk-25
5. Eclipse detects the JDK automatically
6. Rename it to JDK 25
7. Click Finish, check it in the list, Apply and Close

Step 3 — Create a New Java Project


1. File → New → Java Project
2. Project name: JUnit5Demo
3. Use JDK 25 as project JRE
4. Click Finish
Step 4 — Add JUnit 5 Library
1. Right-click the project → Configure Build Path
2. Go to Libraries tab → Click Add Library…
3. Select JUnit → Next → JUnit 5 → Finish
4. Click Apply and Close

✅ Eclipse automatically adds all necessary JUnit 5 jars:

 junit-jupiter-api
 junit-jupiter-engine
 junit-platform-commons

No manual JAR downloads required.

Step 5 — Create the Calculator Class


1. Right-click src → New → Class
2. Name: Calculator
3. Package: testing (optional)

Paste:

package testing;

public class Calculator {

public int add(int a, int b) {


return a + b;
}

public int subtract(int a, int b) {


return a + b;
}

public int multi (int a, int b) {


return a / b;
}

public int divide(int a, int b) {


return a / b;
}

}
Step 6 — Create JUnit 5 Test Class
1. Right-click src → New → JUnit Test Case
2. Class name: CalculatorTest
3. Select JUnit 5
4. Click Finish

Replace content with:

package testing;

import static [Link].*;


import [Link];

class CalculatorTest {

@Test
void testAdd() {
Calculator calc = new Calculator();
assertEquals(5, [Link](2, 3));
}

@Test
void testDivide() {
Calculator calc = new Calculator();
assertEquals(2, [Link](4, 2));
}
}

Step 7 — Run the Test


1. Right-click [Link] → Run As → JUnit Test
2. You should see green bar → all tests passed ✅

No NoClassDefFoundError or module errors.

Can’t Run and Show Error  Delete [Link]

Step 8 — Optional: Set JDK 25 as Default


1. Window → Preferences → Java → Installed JREs
2. Check JDK 25
3. Click Apply and Close

All new projects will now automatically use JDK 25.


Testing Note
1. assertEquals(expected, actual) - Checks that two primitives/objects are equal.

2. assertTrue(boolean condition) - Checks that a condition is true.

3. assertFalse(boolean condition) - Checks that a condition is false.

assertSame(object1, object2) - Checks if two object references point to the same object.

assertNotSame(object1, object2) - Checks if two object references do not point to the same
object.

assertNotNull(Object object) - Checks that an object isn't null.

assertNull(Object object) - Checks that an object is null.

assertArrayEquals(expectedArray, resultArray) - Checks whether two arrays are equal to


each other

[Link]

[Link]

You might also like