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 7592903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:01:30+00:00 2026-05-30T21:01:30+00:00

I’ve got a general question illustrated with a concrete example. How much would you

  • 0

I’ve got a general question illustrated with a concrete example.
How much would you recommend testing composite objects when all the component objects are already tested?

As a concrete example consider the NullTerminatedStringReader below. It reads, from a bytebuffer, a null terminated string. To do this it uses Javas Charset decoder.

I of course want to test my NullTerminatedStringReader. It should be able to read all kinds of strings like UTF8, UTF16, ASCII and so on.

Imagine I had written the CharsetDecoder and tested that it would decode characters from all kinds of possible charsets. It’s REALLY well tested and tried and I have no doubt that it works. Now I write a NullTerminatedStringReader that uses the CharsetDecoder. In theory I want the NullTerminatedStringReader to be able to handle all strings of charsets that the CharsetDecoder can decode. If I was using TDD I would want to drive my design, so I would write a lot of tests testing each charset decoding for NullTerminatedStringReader:

...
void testNullTerminatedStringReaderCanDecodeUTF8String()
void testNullTerminatedStringReaderCanDecodeASCIIString()
...

But this seems redundant because in the test for CharsetDecoder I have all these tests:

...
void testCharsetDecoderCanDecodeUTF8Char()
void testCharsetDecoderCanDecodeASCIIChar()
...

I’m not sure what to do here because without the tests for NullTerminatedStringReader, how can I drive it’s design to support all of these decodings? Am I testing on the wrong level for NullTerminatedStringReader? If I don’t make the tests it also seems something is missing because in theory I know the NullTerminatedStringReader is using CharsetDecoder and I know that all it does is append chars to form a string, so there’s not much that can go wrong here. If CharsetDecoder works so should NullTerminatedStringReader. But what if it didn’t use CharsetDecoder – I think it is more clear to assume no knowledge of NullTerminatedStringReader’s implementation and then write the tests, however this results in what seems like redundant tests.. dillema? You bet.

class NullTerminatedStringReader
{
    private Charset charset;

    public String read(ByteBuffer buffer)
    {
        StringBuilder sb = new StringBuilder();
        while (true)
        {
            char charVal = readChar(buffer, charset.newDecoder()); // unicode char, possibly span several bytes
            if (charVal == '\0')
                break;
            sb.append(charVal);
        }

        return sb.toString();
    }

    private char readChar(ByteBuffer buffer, CharsetDecoder decoder) {...}
}
  • 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-30T21:01:31+00:00Added an answer on May 30, 2026 at 9:01 pm

    When testing a composite object I generally just test for two things:

    • Does it support the composite end-to-end use cases that it is designed for?
    • Does any incremental capability added by the composite object work?

    In general, I wouldn’t try to test the sub-objects comprehensively as they should have their own test cases to do that. i.e. you should assume that your own sub-objects work, in the same way that you assume that java.util.ArrayList works.

    So in your example of the NullTerminatedStringReader, I’d probably only test that it works with one or two alternative charsets (i.e. prove that it is calling the correct CharsetDecoder) and trust that the CharsetDecoder was well enough tested to work will all other charsets.

    • 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 got an object with contents of html markup in it, for example: string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I would like to run a str_replace or preg_replace which looks for certain words
I have just tried to save a simple *.rtf file with some websites and

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.