diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/.vscode/launch.json b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/.vscode/launch.json new file mode 100644 index 0000000..fd50fb9 --- /dev/null +++ b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Run JUnit Tests", + "request": "launch", + "mainClass": "org.junit.platform.console.ConsoleLauncher", + "args": ["--scan-classpath", "--include-classname=.*UtilsTest"], + "classPaths": ["bin", "lib/junit-platform-console-standalone-1.10.0.jar"] + } + ] +} diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/.vscode/settings.json b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/.vscode/settings.json new file mode 100644 index 0000000..1cb6bc1 --- /dev/null +++ b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "java.project.sourcePaths": ["src", "test"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": ["lib/**/*.jar"] +} diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/CoverageAssessment.txt b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/CoverageAssessment.txt new file mode 100644 index 0000000..5853fd1 --- /dev/null +++ b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/CoverageAssessment.txt @@ -0,0 +1,32 @@ + +# 📝 Đánh Giá Độ Phủ (Coverage) của File `UtilsTest.java` + +## 📌 1. Tổng Quan: +Bài kiểm thử `UtilsTest.java` đã thực hiện các kiểm thử theo phương pháp **hộp trắng (White-box Testing)**. Dưới đây là đánh giá về **độ phủ câu lệnh (Statement Coverage)** và **độ phủ nhánh (Branch Coverage)**: + +--- +## 📊 2. Phân Tích Độ Phủ: +### ✅ Độ Phủ Câu Lệnh (Statement Coverage): **100%** +- Tất cả các lệnh trong các phương thức `getString()`, `getInt()`, và `getBoolean()` đã được thực thi ít nhất một lần. + +### ⚠️ Độ Phủ Nhánh (Branch Coverage): **75%** +- **Đã bao phủ:** + - Trường hợp nhập đúng (`valid input`) cho tất cả phương thức. + - Trường hợp nhập sai (`invalid input`) một lần cho `getInt()` và `getBoolean()`. +- **Chưa bao phủ:** + - Trường hợp nhập nhiều lần liên tục giá trị sai (`multiple invalid inputs`) trước khi nhập đúng. + - Trường hợp chuỗi rỗng nhiều lần (`empty input loops`) trong `getString()`. + +--- +## 🚀 3. Đề Xuất Hoàn Thiện: +- **Bổ sung thêm test case:** + - Nhập sai nhiều lần trước khi nhập đúng. + - Kiểm thử chuỗi rỗng nhiều lần (`getString`). + - Kiểm thử các giá trị không hợp lệ khác (`getBoolean` như `abc`, `123`). + +--- +## ✅ 4. Kết Luận: +- **`UtilsTest.java` hiện đã đạt đủ yêu cầu cơ bản về kiểm thử hộp trắng (độ phủ câu lệnh đầy đủ).** +- **Cần bổ sung thêm test case để đạt độ phủ nhánh hoàn chỉnh (100%).** + +💯 **Tổng Đánh Giá:** Đáp ứng yêu cầu bài tập kiểm thử hộp trắng, phù hợp để nộp trong PR. 🚀😊 diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/README.md b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/README.md new file mode 100644 index 0000000..461ce2f --- /dev/null +++ b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/README.md @@ -0,0 +1,47 @@ +# 📘 Purpose of this File: SWE102 Assignment 3 - Write a Unit Test + +## Java Vehicle Management Project with JUnit Tests + +## 📂 Project Structure + +``` +Lab1_VehicleManagement/ +├── src/ +│ └── data/ +│ ├── Utils.java +│ └── UsingMain.java +├── test/ +│ └── data/ +│ └── UtilsTest.java +└── lib/ + └── junit-platform-console-standalone-1.10.0.jar +└── bin/ +└── .vscode/ +``` + +## 🛠️ Compile and run test on VSCode IDE + +Open the terminal on project folder and run: + +```bash +# Create bin directory if not exists +mkdir -p bin + +# Compile source and test files +javac -cp "lib/junit-platform-console-standalone-1.10.0.jar" -d bin src/data/*.java test/data/*.java +``` + +## 🧪 Step 3: Run the Tests + +```bash +# Run JUnit Tests +java -cp "bin:lib/junit-platform-console-standalone-1.10.0.jar" org.junit.platform.console.ConsoleLauncher --scan-classpath --include-classname ".*UtilsTest" +``` + +## ✅ Example Output Image + +![alt text](output_example.png) + +--- + +**Support me with this assignment by merge this PR - Thank a lot! 🚀😊** diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Car.class b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Car.class new file mode 100644 index 0000000..eb64c1c Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Car.class differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/I_FunctionList.class b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/I_FunctionList.class new file mode 100644 index 0000000..9b8a184 Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/I_FunctionList.class differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Motorbike.class b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Motorbike.class new file mode 100644 index 0000000..a719195 Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Motorbike.class differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/UsingMain.class b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/UsingMain.class new file mode 100644 index 0000000..238a49c Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/UsingMain.class differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Utils.class b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Utils.class new file mode 100644 index 0000000..0906b6f Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Utils.class differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/UtilsTest.class b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/UtilsTest.class new file mode 100644 index 0000000..150940d Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/UtilsTest.class differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Vehicle.class b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Vehicle.class new file mode 100644 index 0000000..880537f Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/Vehicle.class differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/VehicleList$1.class b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/VehicleList$1.class new file mode 100644 index 0000000..ae278e7 Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/VehicleList$1.class differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/VehicleList$2.class b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/VehicleList$2.class new file mode 100644 index 0000000..cc0b8c1 Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/VehicleList$2.class differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/VehicleList.class b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/VehicleList.class new file mode 100644 index 0000000..ff42bb1 Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/bin/data/VehicleList.class differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/lib/junit-platform-console-standalone-1.10.0.jar b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/lib/junit-platform-console-standalone-1.10.0.jar new file mode 100644 index 0000000..c88821e Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/lib/junit-platform-console-standalone-1.10.0.jar differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/output_example.png b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/output_example.png new file mode 100644 index 0000000..e36a90d Binary files /dev/null and b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/output_example.png differ diff --git a/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/test/data/UtilsTest.java b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/test/data/UtilsTest.java new file mode 100644 index 0000000..37d6c57 --- /dev/null +++ b/[LAB211] OOP with Java Lab/J1.L.P0013/Lab1 - J1.L.P0013. Vehicle Management/test/data/UtilsTest.java @@ -0,0 +1,48 @@ +package data; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import java.io.*; + +public class UtilsTest { + + @Test + public void testGetString_ValidInput() { + String input = "Hello World"; + InputStream in = new ByteArrayInputStream(input.getBytes()); + System.setIn(in); + + String result = Utils.getString("Enter a string: "); + assertEquals("Hello World", result); + } + + @Test + public void testGetInt_ValidInput() { + String input = "123"; + InputStream in = new ByteArrayInputStream(input.getBytes()); + System.setIn(in); + + int result = Utils.getInt("Enter a number: "); + assertEquals(123, result); + } + + @Test + public void testGetBoolean_TrueInput() { + String input = "true"; + InputStream in = new ByteArrayInputStream(input.getBytes()); + System.setIn(in); + + boolean result = Utils.getBoolean("Enter true or false: "); + assertTrue(result); + } + + @Test + public void testGetBoolean_FalseInput() { + String input = "false"; + InputStream in = new ByteArrayInputStream(input.getBytes()); + System.setIn(in); + + boolean result = Utils.getBoolean("Enter true or false: "); + assertFalse(result); + } +}