• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

JUnit in Action, in chp 1

I was reading the book JUnit in Action, in tat u wrote the first test case in Chapter 1, howerver u did notmhave a import statement for calculator, so u did not need a calcualtor calss and u first worte the test case and then when u get red, u build a class and then run the test case again, so this time it is green now. Is this the ideology of JUnit. To me it seems redundant
  • 3
1 Solution
>> To me it seems redundant
I don't follow that rule myself, but the concept is to make sure that your application do not only function correctly but also function based on the functional requirements.
Before you start a program you have a functional requirement (what the program needs to do) .So, then your write a test case that covers it and only then code your program. This way you will make sure you are not deviating from what you/your functional spec intended and you provide all the needed functionality.
Chakri25Author Commented:
So JUnit is first u write a TestCase for a method X() and then run it , u get a red.
Then u  implement method X() in class Y, then it passes the test and it is Green

Now we already have code written say some classes , we need to use some of the these classes and build new funcationlaity probably a new class and new methods, then it becomes complicated.

Any ideas pls?
You don't have to run it and see "red".
Let say you get a requirement for something. you analyze the problem and create a functional spec for it (or someone else does).
Once you have that you can design your system and build your API and interfaces that should expose the needed functions (no real code yet).
After that you can build your test cases (which can use the provided interfaces).
Then you go and build your code (behind those interfaces and skeletons) and run your tests as you go.
Any further modification (factorization, change due to profiling...) should be covered by those test cases.
Each time you need to change the API (the functional contract of the application) you will need to update your test cases
and re-run them.
Basically, the main idea behind that concept is to make sure that while you develope you don't deviate from the requirements
in addition to testing your code.

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now