aspose file tools*
The moose likes Testing and the fly likes what I can do with junit ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "what I can do with junit ??" Watch "what I can do with junit ??" New topic
Author

what I can do with junit ??

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

Hola all.
I heared alot about junit and how much this framework is important.
but I don't know how junit can be important to me.
usually, I use java to develope java application (swing , web, EJB ..), so how can junit help me ?
thanks.
J. B. Rainsberger
author
Ranch Hand

Joined: Aug 05, 2004
Posts: 87
JUnit can help you test any Java code at all, including J2EE applications. If you can write Java code to invoke it, JUnit can test it.

Where JUnit (indeed, testing in general) becomes powerful is that if your system is well covered by tests that you can run in only seconds or a few minutes, then no matter what change you make to your system, you can do so confidently--if you make an important mistake, your tests will fail and you'll know about it immediately. This is the primary benefit I see with programmer testing.


Author of <a href="http://www.amazon.com/exec/obidos/ASIN/1932394230/ref=jranch-20" target="_blank" rel="nofollow">JUnit Recipes: Practical Methods for Programmer Testing</a>
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Why use JUnit??

Because :

Why Use JUnit?


Before we begin, it's worth asking why we should use JUnit at all. The subject of unit testing always conjures up visions of long nights slaving over a hot keyboard trying to meet the project's test case quota. However, unlike the draconian style of conventional unit testing, using JUnit actually helps you write code faster while increasing code quality. Once you start using JUnit you'll begin to notice a powerful synergy emerging between coding and testing, ultimately leading to a development style of only writing new code when a test is failing.

Here are just a few reasons to use JUnit:


JUnit tests allow you to write code faster while increasing quality.
Yeah, I know, it sounds counter-intuitive, but it's true! When you write tests using JUnit, you'll spend less time debugging, and you'll have confidence that changes to your code actually work. This confidence allows you to get more aggressive about refactoring code and adding new features. Without tests, it's easy to become paranoid about refactoring or adding new features because you don't know what might break as a result. With a comprehensive test suite, you can quickly run the tests after changing the code and gain confidence that your changes didn't break anything. If a bug is detected while running tests, the source code is fresh in your mind, so the bug is easily found. Tests written in JUnit help you write code at an extreme pace and spot defects quickly.

JUnit is elegantly simple.
Writing tests should be simple - that's the point! If writing tests is too complex or takes too much time, there's no incentive to start writing tests in the first place. With JUnit, you can quickly write tests that exercise your code and incrementally add tests as the software grows. Once you've written some tests, you want to run them quickly and frequently without disrupting the creative design and development process. With JUnit, running tests is as easy and fast as running a compiler on your code. In fact, you should run your tests every time you run the compiler. The compiler tests the syntax of the code and the tests validate the integrity of the code.

JUnit tests check their own results and provide immediate feedback.
Testing is no fun if you have to manually compare the expected and actual result of tests, and it slows you down. JUnit tests can be run automatically and they check their own results. When you run tests, you get simple and immediate visual feedback as to whether the tests passed or failed. There's no need to manually comb through a report of test results.

JUnit tests can be composed into a hierarchy of test suites.
JUnit tests can be organized into test suites containing test cases and even other test suites. The composite behavior of JUnit tests allows you to assemble collections of tests and automatically regression test the entire test suite in one fell swoop. You can also run the tests for any layer within the test suite hierarchy.

Writing JUnit tests is inexpensive.
Using the JUnit testing framework, you can write tests cheaply and enjoy the convenience offered by the testing framework. Writing a test is as simple as writing a method that exercises the code to be tested and defining the expected result. The framework provides the context for running the test automatically and as part of a collection of other tests. This small investment in testing will continue to pay you back in time and quality.

JUnit tests increase the stability of software.
The fewer tests you write, the less stable your code becomes. Tests validate the stability of the software and instill confidence that changes haven't caused a ripple-effect through the software. The tests form the glue of the structural integrity of the software.

JUnit tests are developer tests.
JUnit tests are highly localized tests written to improve a developer's productivity and code quality. Unlike functional tests, which treat the system as a black box and ensure that the software works as a whole, unit tests are written to test the fundamental building blocks of the system from the inside out. Developer's write and own the JUnit tests. When a development iteration is complete, the tests are promoted as part and parcel of the delivered product as a way of communicating, "Here's my deliverable and the tests which validate it."

JUnit tests are written in Java.
Testing Java software using Java tests forms a seamless bond between the test and the code under test. The tests become an extension to the overall software and code can be refactored from the tests into the software under test. The Java compiler helps the testing process by performing static syntax checking of the unit tests and ensuring that the software interface contracts are being obeyed.

JUnit is free.




Reference Website
JUnit Primer


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by somkiat puisungnoen:
Why use JUnit??

JUnit Primer


Somkiat, I think you misunderstand what the original poster wants to know. John Todd just wants to know what features are available in JUnit so that he can apply it to the existing application he is currently doing...

You got a pretty nice chunk of explanation from JUnit Primer site...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
J. B. Rainsberger
author
Ranch Hand

Joined: Aug 05, 2004
Posts: 87
There are a number of extensions to JUnit that help testing JDBC code, servlets, JSPs, EJBs, and so on. JUnit can help you write a suite of repeatable, automated tests that give you confidence that any change you make to your system is correct.
Donny Wi
Greenhorn

Joined: Jan 24, 2002
Posts: 13
There is another test framework called "Cactus" that implement JUnit.

This is what they claim....

Cactus is a simple test framework for unit testing server-side java code (Servlets, EJBs, Tag Libs, Filters, ...).

The intent of Cactus is to lower the cost of writing tests for server-side code. It uses JUnit and extends it.


For more information: http://jakarta.apache.org/cactus/


Donny Widjaja
J. B. Rainsberger
author
Ranch Hand

Joined: Aug 05, 2004
Posts: 87
JUnit Recipes includes some information about using Cactus, but since Vince Massol wrote both Cactus and JUnit in Action, you might expect to see a lot of Cactus in JUnit in Action--and there is!

I like Cactus, and I think Cactus is an excellent tool for testing legacy J2EE applications and components; however, Cactus tests execute more slowly than plain JUnit tests (because they run on the server, not because Cactus is poorly written--Cactus is excellent), and so I use Cactus as an intermediate tool to help me get to the point where I can write 95% of my tests without it.

I would never go into a legacy J2EE application without Cactus by my side, but my goal in using it is to get the point where I almost don't need it any more.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what I can do with junit ??
 
Similar Threads
How important is testing our test cases ?
How Ant and JUnit work together?
to use junit
Running JUnit testcases with Maven
JUnit :Test type does not exist