Chuyển tới nội dung chính
kitlocal.dev

Viết test JUnit 5 cho một lớp Java

Sinh một lớp test JUnit 5 (kèm Mockito khi cần) cho một lớp, bao phủ luồng chính, trường hợp biên và lỗi, đồng thời nêu rõ phần chưa kiểm thử.

Prompt là văn bản bạn sao chép vào trợ lý của mình. KitLocal không chạy chúng.

Điền các biến

Những gì bạn gõ chỉ ở trong trình duyệt này. Không được thêm vào URL, không lưu và không gửi đi đâu.

Xem trước

Còn thiếu: Class under test

Write a JUnit 5 test class for the Java class below.

Assertion style: AssertJ
Use Mockito for collaborators: yes

Rules:
- One behavior per test; name tests as should_<behavior>_when_<condition>.
- Cover the happy path, boundary values, null/empty input, and each exception path.
- Do not test private methods directly and do not assert on implementation details.
- Prefer small inline fixtures over shared mutable state.
- After the code, list behaviors you deliberately did NOT test and why.

Collaborators:


Class under test:
```java
{{classUnderTest}}
```

Mục đích

Draft a first, reviewable test class so you start from a solid skeleton instead of a blank file.

Khi nào nên dùng

  • A class has little or no coverage and you need a starting point.
  • You want edge cases you might not think of listed explicitly.

Cần chuẩn bị gì

  • The class under test and the signatures of its direct collaborators.
  • Your assertion library preference.

Đầu ra mong muốn

A single compilable Java test class in one code block, followed by a short "Not covered" list.

Về danh mục này

Bản chụp đi kèm ứng dụng · xuất bản lúc 06:05 15 thg 11, 2026 · Phiên bản danh mục 5bc079fe355af2214bc0

Đang hiển thị bản chụp đi kèm ứng dụng (chưa cấu hình nguồn nội dung). Nguồn có thể đã có nội dung mới hơn.