6

I have an interview coming up soon next week and there's a few things on their list of responsibilties for this software development job (the job position title is vague, it says java developer) that I am worried about:

  • Unit test features
  • Debug new features
  • Provide recommendation on test case design (what is this?)

I am worried because in my past software projects, I have not bothered writing unit tests. I know how to use JUnit to write tests in Eclipse and the process but it's just that I have not much experience writing tests. For example, I rely on data from the web, which varies a lot from each other, and process this data. How can I write test cases for every single type of data? Also, if the data is from a local database, how would I write a test case that checks that data from tables are being read properly?

I've used the debug feature in Eclipse whenever I could, but sometimes, when I am accessing a library which doesn't come ith source code for (e.g. commercial 3rd party Jars), the step into feature would stop. So for most cases, I just System.out.println to discover where the bug is happening. Is there a better method?

How can I practice in the short period of time to be somewhat competent in writing unit test?

  • Welcome to Programmers, javastudent. There are a couple of questions on the site that already cover what you are asking: How to write “good” unit tests?, How do you write unit test cases?. – PersonalNexus Jan 06 '12 at 19:13
  • I've read the first question just now, but I still don't have a picture of what is a "good" unit test. – javastudent Jan 06 '12 at 19:14
  • 1
    "I still don't have a picture of what is a "good" unit test". That comes with practice and reading existing code. Also. "I just System.out.println to discover where the bug is happening". Unit tests aren't really used for debugging. What are you really doing? Writing new code? Or fixing bugs in existing code? Please update the question to clarify. – S.Lott Jan 06 '12 at 19:21
  • 2
    println? OMG use a debugger! – Mike Nakis Jan 06 '12 at 19:58
  • @MikeNakis, yes but if you've used jars with no source available, the debug step into will terminate. Using the jar decompiler plugin in eclipse still doesn't work perfectly. – javastudent Jan 07 '12 at 01:30
  • Okay, I have never tried to debug into a jar file with no source available, other than the standard jar files of the java runtime, so I may be going out on a limb here, but I cannot imagine the situation you are in being awfully different from the situations I have encountered. So: – Mike Nakis Jan 07 '12 at 11:23
  • the debug step into should NOT terminate; I do not know what kind of weird problem you are facing, but I do not think that it is normal behavior. Normal behavior is that if there is no source available, the step into just acts as a step over. 2. In any case, there should be some option to tell the debugger to ignore code for which no source code is available. 3. If you ever find yourself inside a function for which no source is available, there is a debugger command called "step out".
  • – Mike Nakis Jan 07 '12 at 11:25
  • ah okay. where do I find info on the eclipse debugger? – javastudent Jan 07 '12 at 13:16
  • When you reply to someone use '@' + their name so that they get a notification. (You receive this notification because it is your post.) I think that you do not need to find any documentation per se, all you need to do is open the 'Debug' menu and look at what options are available. Learn by monkeying around. It will still be faster than reading a book from start to end. I do not know of any info, so I would do what you can do: google it. – Mike Nakis Jan 07 '12 at 18:21
  • @S.Lott writing new code. – javastudent Jan 08 '12 at 15:35
  • @javastudent: Please update the question with clarification. Do not add comments. – S.Lott Jan 09 '12 at 00:03