Campbell Ritchie wrote:I suggest you start from scratch with your testing class. I can see all sorts of problems with the current code. Some style and some logic problems:-
Always start ClassNames with CapitalLetters. Class Names should be nouns; if you are using adjectives as class names, it suggests to me your class doesn't represent nor constitute an entity in the object‑oriented sense of the word. Don&apo;t risk returning null in line 25: if you have a null throw an exception instead. Only use @SuppressWarnings if you are sure the code it applies to is correct. The following method contains at least four significant errors.. Don't make your class do several things. You have methods to open the connection, to print a JSON and claiming to test something. As you know, a utility class contains only static members, only private constructors to prevent instantiation, and no variables. Usually they contain only methods, one private constructor, and public or private constants. A utility class is intended to be used by other code rather than having an existence as an object in its own right.
For unit testing you test every method available with “normal” and “incorrect” arguments. I would have thought you would be using a framework like JUnit.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:Have you removed the package statements? Please include them. Is Utils in com\root\com?
Zach Rode wrote:I know you asked about testing but your formatting is all over the place too.
That block has all kinds of weird stuff going on. I know it might seem insignificant but when you are having others review your code, it matters for readability purposes and impressions (it's the same as mixing up they're, their, and there when you're inconsistent like that). CTRL+SHIFT+F is your friend if you're using Eclipse.
Just for instance you have 3 different whitespace formats going on with your class/method names
As far as tests code, You've already made this class, so unless you start from scratch you can't exactly implement TDD. Download a code coverage tool (never used that framework so I'm not sure if it comes with one), write logical tests for edge cases and normal cases for each method, run coverage tool, right tests to test what you haven't covered; logical ones, coverage for coverage's sake is bad. Rinse and repeat.
-Zach
Knute Snortum wrote:Have you removed the package statements? Please include them. Is Utils in com\root\com?
Arya Ramanujan wrote:
Knute Snortum wrote:Have you removed the package statements? Please include them. Is Utils in com\root\com?
I did not remove them but just while pasting, I deleted them, thought it may not be necessary.
All things are lawful, but not all things are profitable.
Consider Paul's rocket mass heater. |