Software Testing Engineering / UNIT TEST DESIGN & AUTOMATION / TST-007

Money Unit Tests

Explore concept graph

Praktik dan verifikasi mandiri

Project — Money Unit Tests

Konsep 1 / 3

Write a JUnit Jupiter unit test using Arrange–Act–Assert, @Test and @BeforeEach without Spring context.

Write an independent test for USD 200.00 and verify USD 3.00 using a descriptive name and @Test. Do not inspect implementation internals.

Kasus yang berbeda dari contoh: USD 200.00 instead of the worked IDR 10000 example, with a different currency precision.

Bukti yang bisa kamu periksa

  • A real Jupiter @Test method that runs through Maven and asserts the public returned BigDecimal without Spring.

Jika ingin lanjut

Expand the example into a table of normal, zero, negative and maximum boundary cases.

Jika terputus: Resume by writing one Arrange–Act–Assert assertion for a specific money amount.

Konsep 2 / 3

Check zero/negative amounts, exactly-at-cap and above-cap values, and expected exceptions as separate observable outcomes.

Add USD 1000000.00 and USD 1000000.01 cases, asserting USD 15000.00 versus an exception with no Spring context.

Kasus yang berbeda dari contoh: Test two-decimal USD boundary rather than IDR integer max shown in the worked example.

Bukti yang bisa kamu periksa

  • Passing JUnit test outputs for valid max and above-max USD with explicit expected exception.

Jika ingin lanjut

Test decimal rounding and two different currency scales without floating-point conversions.

Jika terputus: Choose one boundary and write its expected return or exception first.

Konsep 3 / 3

Test rounding near thresholds and enforce IDR/USD minor-unit precision with a reproducible Maven run.

Implement a different threshold test for USD 0.67 and prove USD 0.01, then mutate HALF_UP to DOWN locally to show an existing boundary test fails; restore the implementation before committing.

Kasus yang berbeda dari contoh: A different USD threshold input and deliberate rounding-policy mutation instead of replaying the 0.33/0.34 example.

Bukti yang bisa kamu periksa

  • Maven Surefire report with explicit currency rounding assertions and a documented local mutation that was caught by a failing test, restored to green.
  • No Spring context dependencies or classes in the lab.

Jika ingin lanjut

Connect unit-test evidence to API contract tests later, without conflating pure fee logic with database, Spring MVC or transfer authorization.

Jika terputus: Resume from a small rounding matrix: expected raw fee, target currency scale and expected rounded fee.

Tinjau source Java murni dan tulis pengujian tambahan yang mengamati perilaku fee, bukan urutan pemanggilan internal, konteks Spring, atau representasi UI. Pertahankan dua assertion terpisah di sekitar batas rounding, batas maksimum, dan error input.

Money Unit Tests — JUnit 5 behavior matrix

Buktikan FeeCalculator untuk normal, zero, negative, max, rounding dan USD/IDR dengan JUnit Jupiter, termasuk expected exception, kemudian jalankan semuanya via Maven tanpa Spring context.

Latihan manual — jalankan sendiri di lingkunganmu. Kriteria di bawah adalah pemeriksaan mandiri, bukan penilaian otomatis.

Kriteria selesai

  • Test normal IDR dan USD dengan BigDecimal dari string serta assertion nilai dan scale output.
  • Test zero, negative dengan expected exception, batas maksimum yang valid, dan nominal di atas maksimum.
  • Test HALF_UP pada sisi bawah/atas ambang pembulatan untuk IDR 33/34 dan USD 0.33/0.34.
  • Test principal precision yang tidak valid, unsupported currency dan null input dengan tipe exception yang sesuai.
  • Jalankan mvn clean verify dan lampirkan Surefire report berisi 20 test, zero failures/errors/skipped, bukan screenshot IDE saja.
  • Buktikan satu mutation test manual: ubah sementara HALF_UP menjadi DOWN, tunjukkan test rounding gagal, lalu kembalikan source sebelum akhir.
  • Tegaskan tidak ada Spring ApplicationContext, database, API call, FX conversion atau tarif bank production dalam scope lab.

Kriteria verifikasi mandiri

  • Bisa menjelaskan @Test, @BeforeEach dan Arrange–Act–Assert secara konkret.
  • Bisa menggunakan assertEquals dan assertThrows untuk nominal uang dan error.
  • Dapat membedakan input max yang valid dari nilai over-max yang ditolak.
  • Memahami BigDecimal, skala IDR/USD, dan pembulatan HALF_UP.
  • Dapat menjalankan 20 JUnit tests melalui Maven Surefire tanpa Spring context.