Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JUnit and Testcases



On Mar 31, 2004, at 11:10 PM, Michael McDougall wrote:

I looked for a main before posting. Apparently not carefully enough.


You certainly aren't alone if you think the example that I posted was a bit longer than absolutely necessary; I simply grabbed one of the last testcases that I pulled out of a bug report and transformed into a JUnit test. More than one person has asked for a simpler example showing the flavor of a JUnit test. So...

Try the following:

1) Download JUnit, grab "junit.jar" and put it in your classpath.
(See www.junit.org or junit.sourceforge.net)
(I just stick junit.jar in /Library/Java/Extensions/ because I use it so much)
2) Cut and paste the file below into someplace convenient like /tmp/TrivialTest.java
3) cd /tmp/
4) javac TrivialTest.java
5) java TrivialTest

To see what a failure looks like, change the sense of one of the asserts so that it says myPi > 4.

FYI, if you want to play with JUnit, you could try a current *development* build of NetBeans (as opposed to the soon to be released 3.6 - we recently integrated new Ant based project support, so the development model for NetBeans 4.0 is totally different than 3.6). Just create a project, create a class and add some methods. Right click it and choose Tools | JUnit | Create Tests. It will generate a skeleton test for you, and if you choose Test Project from the Run menu, it will run your tests.

I've been using it for a week now (full disclosure, I work *on* NetBeans as my job), and other than a bit of quirkiness, it's a joy to use. Note there's no support for project-izing existing sources yet - it's still early in 4.0's lifecycle (the project XML file structure is simple if you feel like editing it, though). But for developing tests quickly, and making running tests a routine and painless part of your development cycle, I haven't seen anything better. And the Ant files and everything you create are buildable from command-line ant as well, so there's no getting locked into an IDE's proprietary build system.

To try it out
http://www.netbeans.org/downloads/survey.html#/download/dev/daily/ build200403311800/dev-build-ide-EN-zip.html
feedback and bug reports are welcome.

-Tim
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.