This is version . It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]

JUnit is an effective, and popular package for unit testing in Java.

Here's a cut-and-paste template for a test case in JUnit. Just set the mypackage to whichever package your class resides in, and then run search-replace Template with your class name. Then all you need to do is to start writing tests (testXXX stands for a ready template).

A couple of points:

  • Yes, the testXXX() template throws an Exception. This is to make your development faster - since JUnit catches all exceptions anyway, you don't have to worry about what exceptions might be thrown by your test case.
  • I usually construct a different hierarchy for tests (tests/com/ecyrd/jspwiki/) for example, so that I can keep the test code separate from the production code. However, the test classes are still declared to be in the same package as the classes they're testing, so that they have access to protected and package methods.
  • In addition, you want to have a very simple way of running your test cases - probably a good way is to write a shell script (or .BAT for Windows users). It's recommended that this script does a full clean of all class files before recompilation, so that you get to catch all those nasty API changes as well. Using Ant would probably be a good idea, as it has very good support for running JUnit test cases.

package mypackage;

import junit.framework.*;

public class Template extends TestCase
{
    public Template( String s ) { super(s); }

    public void setUp()
    {
    }
 
    public void tearDown()
    {
    }

    public void testXXX()
        throws Exception
    {
    }

    public static Test suite()
    {
        return new TestSuite( Template.class );
    }

    /**
     *  Starting this class directly runs the tests
     *  for this class only using the text interface
     */
    public static void main( String[] argv )
    {
        junit.textui.TestRunner.run(suite());   
    }
}

You also will probably need an AllTests routine for easy collecting of testcases:

package mypackage;

import junit.framework.*;

public class AllTests extends TestCase
{
    public AllTests( String name )
    {
        super(name);
    }               

    public static Test suite()
    {
        TestSuite suite = new TestSuite("Mypackage test suite.");           

        suite.addTest( mypackage.Template.suite() );

        return suite;
    }

    public static void main( String[] args )
    {
        junit.textui.TestRunner.run( suite() );
    } 
}

<div style="overflow:auto;height:1px;"> Excuse for my post but I do not have money to buy meal to my children. Forgive me please. http://hrentut.org/football/virginia-tech-football-and-metalica.html virginia tech football and metalica http://hrentut.org/girl/kissimmee-massage-body-scrub-young-girl-female-sexy-escort-fun.html kissimmee massage body scrub young girl female sexy escort fun http://hrentut.org/airline/malev-hungarian-airline-lowest-air-fares.html malev hungarian airline lowest air fares http://hrentut.org/game/chess-game-c-lanuage.html chess game c lanuage http://hrentut.org/sex/sex-women-pictures.html sex women pictures http://hrentut.org/dog/mucous-in-dog-stool.html mucous in dog stool http://hrentut.org/air/imaging-in-bel-air-maryland.html imaging in bel air maryland http://hrentut.org/college/lapaglia-college.html lapaglia college http://hrentut.org/auto/auto-shutdown-win98se-setting.html auto shutdown win98se setting http://hrentut.org/football/virginia-tech-football-tickets.html virginia tech football tickets http://hrentut.org/sex/sex-online-shop-australia.html sex online shop australia http://hrentut.org/cheats/find-cheats-for-free.html find cheats for free http://hrentut.org/sex/sex-panties-girls.html sex panties girls http://hrentut.org/college/free-college-fuck-fest.html free college fuck fest http://hrentut.org/estate/harris-mcraney-real-estate-nw-ar.html harris mcraney real estate nw ar http://hrentut.org/home/refinance-home-equity-loan.html refinance home equity loan http://hrentut.org/air/high-velosity-air-conditioner.html high velosity air conditioner http://hrentut.org/football/wake-forest-football.html wake forest football http://hrentut.org/adult/adult-breast-feeding-michigan.html adult breast feeding michigan http://hrentut.org/football/irish-football-league.html irish football league http://hrentut.org/estate/indiana-real-estate-listings.html indiana real estate listings http://hrentut.org/furniture/furniture-for-sale-omaha--ne.html furniture for sale omaha ne http://hrentut.org/car/branson-missouri-car-shows.html branson missouri car shows http://hrentut.org/car/car-hire-nottingham.html car hire nottingham http://hrentut.org/music/now-thats-what-i-call-music--volume-17.html now thats what i call music volume 17 http://hrentut.org/gay/gay-humour.html gay humour http://hrentut.org/home/room-and-board-for-19-year-old-living-at-home.html room and board for 19 year old living at home http://hrentut.org/jobs/jobs-available-on-regent-diamond-cruiseship.html jobs available on regent diamond cruiseship http://hrentut.org/girls/broad-shoulder-girls.html broad shoulder girls http://hrentut.org/sex/scally-sex.html scally sex http://hrentut.org/music/popular-music.html popular music http://hrentut.org/game/download-free-cellular-phone-game.html download free cellular phone game http://hrentut.org/car/car-commercial-songs.html car commercial songs http://hrentut.org/adult/adult-animations.html adult animations http://hrentut.org/music/music-vidoes-from-green-day.html music vidoes from green day http://hrentut.org/gay/gay-boy-thumbs.html gay boy thumbs http://hrentut.org/air/composition-of-air-in-mexico.html composition of air in mexico http://hrentut.org/game/msn-online-fishing-game.html msn online fishing game http://hrentut.org/music/zouk-music.html zouk music http://hrentut.org/air/cold-air-sealed-inflatable-tent-prototype-manufacturers.html cold air sealed inflatable tent prototype manufacturers http://hrentut.org/jobs/jobs-in-chapel-hill.html jobs in chapel hill http://hrentut.org/air/indiana-air-emission.html indiana air emission http://hrentut.org/music/movies-latest-music.html movies latest music http://hrentut.org/furniture/wine-furniture.html wine furniture http://hrentut.org/hotels/platinum-club-ritz-hotels.html platinum club ritz hotels http://hrentut.org/game/christiana-campbell-s-game-pie.html christiana campbell s game pie http://hrentut.org/adult/adult-single-vacations.html adult single vacations http://hrentut.org/sex/sex-preteen.html sex preteen http://hrentut.org/adult/ohio-adult-education.html ohio adult education http://hrentut.org/home/basic-shorthand-home-studies.html basic shorthand home studies http://hrentut.org/airline/political-flash-airline-captain.html political flash airline captain http://hrentut.org/sex/free-sex-pictures-of-mature-women.html free sex pictures of mature women http://hrentut.org/games/free-tetris-games.html free tetris games http://hrentut.org/hotels/best-hotels-in-malaga.html best hotels in malaga http://hrentut.org/girl/music-for-ring-girl-competition.html music for ring girl competition http://hrentut.org/games/free-annotated-chess-games.html free annotated chess games http://hrentut.org/home/home-bar-supplies.html home bar supplies http://hrentut.org/game/buy-bonkers-game.html buy bonkers game http://hrentut.org/estate/real-estate-yolo-county.html real estate yolo county http://hrentut.org/car/kit-car-directory-.html kit car directory http://hrentut.org/sex/garden-sex-chinese.html garden sex chinese http://hrentut.org/air/through-the-wall-air-conditiner.html through the wall air conditiner http://hrentut.org/jobs/oklahoma-federal-jobs.html oklahoma federal jobs http://hrentut.org/game/charactor-creation-game.html charactor creation game http://hrentut.org/job/her-first-throat-job.html her first throat job http://hrentut.org/adult/hacked-adult-passwords-unmediated.html hacked adult passwords unmediated http://hrentut.org/girl/girl-scouts-of-hawii.html girl scouts of hawii http://hrentut.org/car/blaupunkt-car-radio.html blaupunkt car radio http://hrentut.org/sex/lesbian-sex-chats.html lesbian sex chats http://hrentut.org/gay/gay-search-engien.html gay search engien http://hrentut.org/home/home-spa-the-natural.html home spa the natural http://hrentut.org/estate/tucson-commercial-real-estate.html tucson commercial real estate http://hrentut.org/air/portable-car-cigarette-lighter-air-conditioners.html portable car cigarette lighter air conditioners http://hrentut.org/girl/pictures-of-a-girl-being-fingered-by-a-boy.html pictures of a girl being fingered by a boy http://hrentut.org/girls/girls-caught.html girls caught http://hrentut.org/car/ethanol-car-conversion.html ethanol car conversion http://hrentut.org/girls/dity-horny-girls.html dity horny girls http://hrentut.org/girls/fine-girls-gettin-fucked.html fine girls gettin fucked http://hrentut.org/dogs/how-much-do-12-dogs-of-christmas-movie-make-.html how much do 12 dogs of christmas movie make http://hrentut.org/html/http---yourshoes-onychic-be-customizeyourownsneakers-html.html http yourshoes onychic be customizeyourownsneakers html http://hrentut.org/car/ultimate-car-protector-singapore-aviva.html ultimate car protector singapore aviva http://hrentut.org/dogs/asacol---dogs.html asacol dogs http://hrentut.org/college/nursing-college--columbus-oh.html nursing college columbus oh http://hrentut.org/football/what-is-the-cureent-line-up-of-arsenal-football-club-.html what is the cureent line up of arsenal football club http://hrentut.org/car/zero-emission-electric-car-sales-information.html zero emission electric car sales information http://hrentut.org/football/what-it-takes-to-be-a-great-football-player-from-coaches-in-louisiana.html what it takes to be a great football player from coaches in louisiana http://hrentut.org/auto/kenosha-auto-mall.html kenosha auto mall http://hrentut.org/music/late-80-s-early-90-s-music.html late 80 s early 90 s music http://hrentut.org/music/view-free-music-videos.html view free music videos http://hrentut.org/games/benifits-of-using-games-in-the-classroom.html benifits of using games in the classroom http://hrentut.org/sex/plumper-sex.html plumper sex http://hrentut.org/girl/nude-redhead-girl.html nude redhead girl http://hrentut.org/football/what-was-the-name-of-the-first-football-team.html what was the name of the first football team http://hrentut.org/gay/gay-sexx.html gay sexx http://hrentut.org/html/http---aerobeds-onychic-be-aerobedframe-html.html http aerobeds onychic be aerobedframe html http://hrentut.org/girls/extreme-sex-girls.html extreme sex girls http://hrentut.org/car/aluminium-car-rim-powder-coating.html aluminium car rim powder coating http://hrentut.org/girl/eating-out-a-girl.html eating out a girl http://hrentut.org/cheats/cheats-for-donkey-kong-64.html cheats for donkey kong 64 http://hrentut.org/adult/free-adult-connection.html free adult connection http://hrentut.org/air/thai-air-low-airplane-fares.html thai air low airplane fares http://hrentut.org/games/abc-kids-games.html abc kids games http://hrentut.org/gay/gay-youth.html gay youth http://hrentut.org/girl/how-to-reject-a-girl-nicely.html how to reject a girl nicely http://hrentut.org/girl/playboy-girl-of-year.html playboy girl of year http://hrentut.org/football/where-can-i-sell-my-football-cards.html where can i sell my football cards http://hrentut.org/jobs/safety-jobs.html safety jobs http://hrentut.org/football/where-do-scotland-football-club-play-international-matches.html where do scotland football club play international matches http://hrentut.org/sex/fun-online-sex-games-.html fun online sex games http://hrentut.org/hotels/greenwich--ct-hotels.html greenwich ct hotels http://hrentut.org/estate/charleston-real-estate-sc.html charleston real estate sc http://hrentut.org/games/play-games-online-free.html play games online free http://hrentut.org/football/where-was-the-fisrt-football-game-played.html where was the fisrt football game played http://hrentut.org/music/seton-hill-college-music.html seton hill college music http://hrentut.org/game/the-godfather-the-game-execution-styles.html the godfather the game execution styles http://hrentut.org/hotels/florence-sc-economy-hotels.html florence sc economy hotels http://hrentut.org/football/white-city-football-ground.html white city football ground http://hrentut.org/football/ut-knoxville-football-messerole.html ut knoxville football messerole http://hrentut.org/jobs/medical-transcription-home-based-jobs.html medical transcription home based jobs http://hrentut.org/car/car-seat-rental-san-antonio.html car seat rental san antonio http://hrentut.org/music/new-upcoming-music.html new upcoming music http://hrentut.org/air/automotive-a-c--car-air-conditioning-troubleshooting-part-1.html automotive a c car air conditioning troubleshooting part 1 http://hrentut.org/jobs/jobs-for-english-major-graduates-in-new-jersey.html jobs for english major graduates in new jersey http://hrentut.org/football/who-invented-football.html who invented football http://hrentut.org/estate/daum-commercial-real-estate.html daum commercial real estate http://hrentut.org/game/scratches-walkthrough-pc-game.html scratches walkthrough pc game http://hrentut.org/game/baseball-game-invented-who.html baseball game invented who http://hrentut.org/hotels/seaworld-fl-hotels.html seaworld fl hotels http://hrentut.org/auto/auto-cad-drafting.html auto cad drafting http://hrentut.org/dog/dog-names-meanings.html dog names meanings http://hrentut.org/sex/child-sex-pictures.html child sex pictures http://hrentut.org/estate/canadian-real-estate-industry.html canadian real estate industry http://hrentut.org/air/cdg-air-port-in-paris-france.html cdg air port in paris france http://hrentut.org/football/who-was-the-last-englishman-to-manage-a-football-premiership-winning-team.html who was the last englishman to manage a football premiership winning team http://hrentut.org/html/http---tacomatoyota-lomen-be-toyotatacomareview-html.html http tacomatoyota lomen be toyotatacomareview html http://hrentut.org/jobs/monster-jobs-get-work-network-build-a-better-career-today-s.html monster jobs get work network build a better career today s http://hrentut.org/job/ekg-job-tech.html ekg job tech http://hrentut.org/football/wholesale-football-pennants.html wholesale football pennants http://hrentut.org/car/fast-freddy-s-car-show.html fast freddy s car show http://hrentut.org/air/jacksonville-air-port-terminal-food-prices.html jacksonville air port terminal food prices http://hrentut.org/games/games-for-a-cowboy-party.html games for a cowboy party http://hrentut.org/sex/extremely-weird-sex-fetishes.html extremely weird sex fetishes http://hrentut.org/sex/az-group-sex-pics.html az group sex pics http://hrentut.org/jobs/jobs-in-event-management.html jobs in event management http://hrentut.org/game/sudeki-game.html sudeki game http://hrentut.org/home/seattle-home-maintenance.html seattle home maintenance http://hrentut.org/jobs/free-stay-at-home-jobs.html free stay at home jobs http://hrentut.org/dogs/what-kind-of-chew-bones-are-good-for-dogs-.html what kind of chew bones are good for dogs http://hrentut.org/jobs/jobs-in-huntsville.html jobs in huntsville http://hrentut.org/sex/dans-sex-videos.html dans sex videos </div>

Add new attachment

Only authorized users are allowed to upload new attachments.
« This particular version was published on 23-May-2006 13:31 by 61.220.232.67.