JUnit in Action, in chp 1

Posted on 2005-04-26
Last Modified: 2010-03-31
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
Question by:Chakri25
    LVL 15

    Accepted 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.

    Author Comment

    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?
    LVL 15

    Expert Comment

    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.
    LVL 15

    Expert Comment

    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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now