Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1025627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:57:22+00:00 2026-05-16T11:57:22+00:00

I’m learning Java by reading Head First Java and by doing all the puzzles

  • 0

I’m learning Java by reading “Head First Java” and by doing all the puzzles and excercies. In the book they recommend to write TestDrive classes to test the code and clases I’ve written, that’s one really simple thing to do, but by doing this I think I can’t fully test my code because I’m writing the test code knowing what I want to get, I don’t know if it makes any sense, but I was wondering if there’s any way of testing my code in a simple way that it tell’s me what isn’t working correctly. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:57:23+00:00Added an answer on May 16, 2026 at 11:57 am

    What do we mean by code? When Unit testing, which is what I think we’re talking about here, we are testing specific methods and classes.

    I think I can’t fully test my code
    because I’m writing the test code
    knowing what I want to get

    In other words you are investigating whether some code fulfils a contract. Consider this example:

     int getInvestvalue( int depositCents, double annualInterestRate, int years) {
    
     }
    

    What tests can you devise? If you devise a good set of tests you can have some confidence in this routine. So we could try these kinds of input:

      deposit 100, rate 5.0, years 1 : expected answer 105
      deposit 100, rate 0, years 1 : expected answer 100
      deposit 100, rate 10, years 0 : expected anwer 100
    

    What else? How about a negative rate?

    More interestingly, how about a very high rate of interest like 1,000,000.50 and 100,000 years, what happens to the result, would it fit in an integer – the thing about devising this test is that it challenges the interface – why is there no exception documented?

    The question then comes: how do we figure out those test cases. I don’t think there is a single approach that leads to building a comprehensive set but here’s a couple of things to consider:

    1. Edges: Zero, one, two, many. In my example we don’t just do a rate of 5%. We consider especially the special cases. Zero is special, one is special, negative is special, a big number is special …
    2. Corner cases: combinations of edges. In my example that’s a large rate and large number of years. Picking these is something of an art, and is helped by our knowledge of the implmentation: here we know that there’s a “multiplier” effect between rates and years.
    3. White box: using knowldge of the implementation to drive code coverage. Adjusting the inputs to force the code down particiular paths. For example if yoiu know that the code has a “if negative rate” conditional path, then this is a clue to include a negative rate test.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.