Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"java.project.sourcePaths": ["src", "test"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": ["lib/**/*.jar"]
}
Original file line number Diff line number Diff line change
@@ -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. 🚀😊
Original file line number Diff line number Diff line change
@@ -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! 🚀😊**
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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);
}
}