Oriental University Students: Unit Testing With JUnit in Your First Java Internship

Facebook
Twitter
LinkedIn
WhatsApp
Email

When a mentor says “add tests” in your first Java internship, start with the code that handles money, boundaries and invalid input, and write small JUnit tests that each check one behaviour. Use a consistent naming pattern, cover the normal case first, then edges, then failures. This guide gives you a checklist, a naming pattern and a sample test table for a billing calculator, all fitted to a 14-day internship.

What “add tests” actually means to a mentor

The phrase is vague on purpose. A mentor usually means: prove that the code you wrote (or the code you were handed) does what the ticket says, and make sure it keeps doing so after someone else changes it. That is all a unit test is. It is a small Java method that calls one piece of code with known input and checks the output.

In enterprise Java teams, tests are also a communication tool. A reviewer reads your tests to learn what you believed the code should do. Clear tests shorten code review, and that is why mentors ask for them from interns early.

Before writing anything, ask your mentor three questions in writing (a chat message is fine):

  • Which JUnit version does this project use, JUnit 4 or JUnit 5 (Jupiter)? The imports and annotations differ.
  • Is there an existing test class I should copy the style from?
  • How do I run the tests: through the IDE, mvn test or gradle test?

The 14-day plan for learning JUnit alongside your tasks

A short internship leaves no time for a long testing course. This plan fits testing into the work you are already doing. Adjust it to your mentor’s task list.

Days Focus What you should have by the end
1-2 Set up and read Project builds; you can run existing tests; you have read two or three existing test classes
3-4 First tests One test class for a simple method with happy-path tests, using the naming pattern below
5-7 Boundaries and failures Edge-case and exception tests for the same class; a failing test you deliberately broke and fixed
8-10 Test your own feature Tests written alongside the code your mentor assigned
11-12 Clean up Duplicate setup moved into a setup method; names reviewed; no dead or commented-out tests
13-14 Review and hand-off Mentor feedback applied; a short note on what is covered and what is not

The free two-week online internship from CareerSwami follows the same 14-day length, so this schedule works as a template for it. CareerSwami offers a free offer letter and a free completion certificate after successful completion, across 26 tracks.

Free 2-Week CareerSwami Internship

Online, 14 days, with a free offer letter and a free completion certificate once you finish the work. Check with your college that it fits your requirement before you enrol.

Apply for the free internship

JUnit starter checklist for your first Java internship

Work through this list in order. Tick each item before you move on.

Setup

  1. Confirm the JUnit version (4 or 5) from the project’s pom.xml or build.gradle.
  2. Place test classes in src/test/java, in the same package as the class under test.
  3. Name the class ClassNameTest, for example BillingCalculatorTest.
  4. Run the existing tests once before changing anything, so you know the starting state.

Writing each test

  1. One test method checks one behaviour.
  2. Follow the arrange, act, assert order: set up input, call the method, check the result.
  3. Use the most specific assertion available: assertEquals, assertThrows, assertTrue.
  4. Avoid logic (loops, if statements) inside a test.
  5. Do not depend on test order, the clock, the network or a real database in a unit test.

Before you push

  1. All tests pass locally, including the ones you did not write.
  2. Each new test has failed at least once when you broke the code on purpose (this proves it can detect a bug).
  3. Test names read like sentences.
  4. No System.out.println used as a substitute for an assertion.

A test-naming pattern you can use from day one

Pick one pattern and use it everywhere. A widely used one is:

methodName_condition_expectedResult

Examples (illustrative):

  • calculateTotal_emptyCart_returnsZero
  • applyDiscount_percentAbove100_throwsIllegalArgumentException
  • calculateTax_standardRate_addsEighteenPercent

If the team already uses a different style, such as shouldReturnZeroWhenCartIsEmpty or JUnit 5’s @DisplayName, follow the team’s style. Consistency matters more than which pattern you pick.

What to test first when the instruction is just “add tests”

Use this priority order. It puts your limited hours where bugs are most costly.

  1. The main success path. One valid input, one expected output. If this fails, nothing else matters.
  2. Calculations involving money, quantity or dates. Rounding, tax and discount errors reach customers directly.
  3. Boundaries. Zero, one, the largest allowed value, exactly at a threshold, just above and just below.
  4. Invalid input. Null, negative numbers, empty strings, unsupported values. Decide with your mentor whether the code should throw an exception or return a default.
  5. Branches you added or changed. Every if you wrote deserves a test for each side.
  6. Bugs already reported. Write a test that reproduces the bug first, then fix it.

Leave getters, setters and framework wiring for later. They rarely contain logic and they use up time you need for the items above.

Sample test table for a billing calculator

The table below is illustrative. It assumes a hypothetical BillingCalculator class with a method that takes a unit price, a quantity and a discount percentage, then applies 18% GST. The rules are invented for teaching and are not taken from any real system. Confirm the real rules with your mentor before copying any expected value.

# Test name Input (price, qty, discount %) Expected result Why it matters
1 calculateTotal_singleItemNoDiscount_addsGst 100.00, 1, 0 118.00 Main success path
2 calculateTotal_multipleItems_multipliesQuantity 50.00, 3, 0 177.00 Quantity handling
3 calculateTotal_tenPercentDiscount_discountsBeforeGst 200.00, 1, 10 212.40 Order of operations
4 calculateTotal_zeroQuantity_returnsZero 100.00, 0, 0 0.00 Lower boundary
5 calculateTotal_fullDiscount_returnsZero 100.00, 2, 100 0.00 Upper discount boundary
6 calculateTotal_roundingNeeded_roundsToTwoDecimals 33.33, 3, 0 117.99 (check the rounding rule) Rounding policy
7 calculateTotal_negativePrice_throwsIllegalArgumentException -10.00, 1, 0 Exception Invalid input
8 calculateTotal_discountAbove100_throwsIllegalArgumentException 100.00, 1, 101 Exception Invalid input
9 calculateTotal_negativeQuantity_throwsIllegalArgumentException 100.00, -1, 0 Exception Invalid input

Notice that rows 1 to 3 cover normal behaviour, rows 4 to 6 cover boundaries and rounding, and rows 7 to 9 cover failures. That is the same order as the priority list above.

Worked illustration: turning table rows 1, 3 and 7 into JUnit 5 code

This sketch is illustrative and has not been compiled or run. It assumes JUnit 5 and a BillingCalculator that uses BigDecimal. Adapt names to your project.

import static org.junit.jupiter.api.Assertions.*;
import java.math.BigDecimal;
import org.junit.jupiter.api.Test;

class BillingCalculatorTest {

    private final BillingCalculator calculator = new BillingCalculator();

    @Test
    void calculateTotal_singleItemNoDiscount_addsGst() {
        BigDecimal total = calculator.calculateTotal(
            new BigDecimal("100.00"), 1, 0);
        assertEquals(new BigDecimal("118.00"), total);
    }

    @Test
    void calculateTotal_tenPercentDiscount_discountsBeforeGst() {
        BigDecimal total = calculator.calculateTotal(
            new BigDecimal("200.00"), 1, 10);
        assertEquals(new BigDecimal("212.40"), total);
    }

    @Test
    void calculateTotal_negativePrice_throwsIllegalArgumentException() {
        assertThrows(IllegalArgumentException.class, () ->
            calculator.calculateTotal(new BigDecimal("-10.00"), 1, 0));
    }
}

Two points to take from this. First, BigDecimal.equals compares scale as well as value, so 118.0 and 118.00 are not equal; if your project cares only about value, use compareTo. Second, the exception test names the exact exception type, which is more useful than catching a generic Exception.

Oriental University students: what is and is not known about internship rules

Oriental University is a private university in Indore, Madhya Pradesh. The one official document verified for this guide is the university’s Training and Consultancy Policy 2019-20, and it covers training and consultancy work done by faculty and staff. It is not a student internship rule, so it tells you nothing about how an internship, a certificate or a testing exercise counts towards your degree.

The same PDF gives the campus address as Jakhiya, Opp. Rewati Range, Gate No. 1, Sanwer Road, Indore. That is useful for identifying the right institution when you write to an office, but it is not a rule about training.

In practice, this means you should not assume anything about your programme’s internship duration, credit, evaluation format, required documents or whether an online internship is accepted. Those details vary by programme and by scheme year, and they were not verified here. The JUnit skills in this article are useful regardless, because tests and clean code are what a Java mentor will look at. What a certificate counts for at your university is a separate question for your department.

Verification steps for Oriental University students before you rely on an internship

  1. Find your programme’s scheme or regulation booklet for your admission year and look for the training, internship or project clause.
  2. Email your department coordinator and ask: “Is a 14-day online internship acceptable for any requirement in my programme, and in what form?” Keep the reply.
  3. Ask the training and placement office whether an offer letter and completion certificate from an online provider are accepted as supporting documents.
  4. Ask whether a report, presentation or viva is expected, and request the template if one exists.
  5. Confirm the semester or break dates in the current academic calendar so the 14 days do not clash with exams.

How to ask your mentor for feedback on your tests

Do not send a pull request and wait. Add a short note that makes review easy:

  • List what the tests cover: “success path, three boundaries, three invalid inputs.”
  • List what is deliberately not covered: “rounding rule unclear; need your decision.”
  • Ask one specific question: “Should negative quantity throw or return zero?”

Mentors respond better to specific questions than to “please review.” A clear note also shows that you understand the difference between tested and untested behaviour.

Habits that make a beginner’s JUnit tests fragile

  • Testing several behaviours in one method. When it fails, you cannot tell which behaviour broke. Split it.
  • Using double for money. Floating-point errors cause surprising failures. Ask whether the project uses BigDecimal or integer paise.
  • Copying the implementation into the test. If the test repeats the formula, it will repeat the bug too. Use hand-calculated expected values.
  • Writing tests that pass without asserting anything. A test with no assertion cannot fail for the right reason.
  • Relying on shared state. A static field changed by one test can break another. Create fresh objects per test.
  • Chasing a coverage number. High coverage with weak assertions gives false comfort. Meaningful checks matter more.

A short self-review before you mark the testing task done

  1. Can a stranger understand each test from its name alone?
  2. Does every business rule in the ticket have at least one test?
  3. Have I tested zero, one, the limit and past the limit?
  4. Do invalid inputs behave the way my mentor agreed?
  5. Do the tests pass on a clean checkout, not just on my machine?

Frequently Asked Questions

Should I use JUnit 4 or JUnit 5 in my internship?

Use whichever the project already uses. Check the build file for the dependency. New projects tend to use JUnit 5, but mixing versions in one project causes confusing errors, so follow what is there and ask your mentor if unsure.

How many tests are enough for one small class?

There is no fixed number. A reasonable target is one test for the success path, a few for boundaries, and one for each invalid input the code is supposed to reject. For the billing example above, nine tests cover the stated rules.

What is the difference between assertEquals and assertThrows?

assertEquals compares an expected value with the actual result. assertThrows checks that a piece of code throws a particular exception type. Use the second for invalid input rules.

Do I need Mockito in a first internship?

Not at the start. Begin with pure logic such as calculators and validators, which need no mocks. Mockito becomes useful when the class under test depends on a repository or an external service, and your mentor will tell you when to use it.

Why did my test fail even though the numbers look the same?

With BigDecimal, equals considers scale, so 118.0 and 118.00 differ. Either build the expected value with the same scale or compare using compareTo, if your team agrees on it.

Will a JUnit exercise count towards my Oriental University requirements?

That depends on your programme’s rules, which were not verified for this guide. Ask your department coordinator in writing and keep the reply. The verification steps in the Oriental University section above list what to ask.

Can I finish learning JUnit within a 14-day internship?

You can learn enough to write clear, useful tests for simple classes. Mastery of mocking, parameterised tests and integration testing takes longer. Focus on the priority list and the checklist, and treat the rest as follow-up learning.

What should I do if the existing code has no tests and is hard to test?

Do not rewrite it on your own. Tell your mentor what makes it hard, for example hidden dependencies or very long methods, and agree on a small first step, such as testing one pure method or extracting one calculation into its own method.

Related Java & Enterprise Software guides

Ready to put this into practice?

Join the free two-week CareerSwami online internship in Java & Enterprise Software. The internship, the offer letter and the completion certificate are free.

Start your free 2-week internship

Web Stories

Scroll to Top