• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

New to Junit

 
Ranch Hand
Posts: 69
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am kind of new to writing JUNIT test cases.Though I have tried to write 2 or 3 junit classes, I think I do not know the basic concept of writing JUnit.Please tell me what should I start with.Also I am using NetBeans as my IDE.If you can also tell how NetBeans support Junit that will be great.

Regards,
Anila
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you already read http://junit.sourceforge.net/doc/testinfected/testing.htm ?
 
Anila Mathew
Ranch Hand
Posts: 69
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I have gone through this.But the problem I am facing now is I have to write JUNIT for code that is already existing.
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be a good idea for you to tell us more detail about the sort of code you wish to test. If you can show us the methods of a class or the API that you want to test, we can probably talk you through the thought processes when setting up a JUnit test.

It's quite likely, though, that your existing code was not designed to be very testable. JUnit is still useful, but you may find that you need to use some "tricks of the trade" to test things.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Testing existing code isn't easy, because most often it isn't written with testability in mind. You could write whole books about the topic.

Fortunately, Micheal Feathers already did us the favor: "Working Effectively With Legacy Code" is what you want to read. It might be a little bit of a tough read if you are new to JUnit, though...
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Late post sorry.

I'd recommend you skill up on refactoring before you delve too much into writing the junit tests for legacy code. The reason is that refactoring the code will save you from having to write a lot of supporting test code. For example, you won't have as many anonymous inner classes.

For me, the basic procedure would be something like:
1) Examine the code and notice a test case
2) Is the test case easy to write? If so, write it, goto 1. Else 3.
3) refactor out a chunk of code in the vacinity of what you want to test. Goto 2.

Repeat the above until you're exhausted.
[ October 26, 2006: Message edited by: Tony Smith ]
 
Do you pee on your compost? Does this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic