What is the standard for testing in Java? - java

What apps would you use? Are there auto testing suites like autotest for ruby? What do you use and why? To be honest, I don't even know how to write tests, when, or why. I'd like to learn though, I know that it will make me a better developer.
Our team uses Netbeans, not eclipse, although I'm going to still google eclipse responses to see if they are implemented as a Netbeans solution as well.

There are 2 most popular frameworks for unit tests: JUnit and TestNG. Both are annotation based. To create test you have to create class and mark each method that performs test using annotation #Test.
JUnit is older and have more extensions (DBUnit, Cactus etc). TestNG has much more annotations. Very important feature of TestNG is ability to create test groups using annotations.
Yet another group of tools you will probably need is mocking tools (EasyMock, EasyMock etc.)

There are a bunch of testing frameworks that are popular. JUnit is pretty good and comes by default with Eclipse. It provides an API for defining tests and doing assertions, as well as a Testrunner to execute the tests. EasyMock and Mockito work well with JUnit to provide mocking functionality so you can test components in isolation.
For continuous integration, there is Jenkins, which is free.
There are others as well.

I would use junit and possibly a mocking library like jmock.
Most of the automatic "tests" which can be done use the compiler or a code analysis tool like FindBugs.

In addition to what has already been said (JUnit, EasyMock, ...) you may also have a look at Fitnesse: it may be a good tool for full integration and acceptance tests!

Don't forget TestNG. It's the "next generation" beyond JUnit. It handles threaded tests better.
SOAP UI is the right tool for testing SOAP web services.
JMeter or Grinder for load testing.

As JUnit and Mockito was already mentioned, You can look into Infinitest or JUnit Max for autotesting.
http://infinitest.github.com/
http://junitmax.com/

If you are looking for something that implements continuous testing I can recommend two free products:
For a developer during work in Eclipse/IntelliJ IDE:
http://infinitest.github.com/
Infinitest is an Eclipse/IntelliJ plugin that runs your test continuously in the background while you are developing your code.
For a team:
http://hudson-ci.org/
or
http://jenkins-ci.org/
are great continuous integration servers that can do builds and run tests continuously.

Been writing junits for over 7 years now and I highly recommend spock for all your testing needs: unit and integration testing, mocking, end-to-end testing, data driven testing etc

Related

Unit testing framework for my own android library

I'm building an android library for Android developers.
I want start unit testing my library and I'm looking for a good framework.
I saw many articles about Robolectric, but the problem is my library doesn't contain a lot of UI/Activities/Services or other Android elements.
I want to use Robolectric for regular java unit testing, and in not many cases where I need Robolectric for UI/Services test I'll use the Robolectic features.
My questions are:
1. Can I use Robolectric for pure java unit testing? And if I can, I will be happy to get a good tutorial for this.
2. Does Robolectric is the best framework for my needs?
The short answer is yes.
You can setup your project with robolectric & Junit4. Then, when you have tests that do not touch any Android-specific bits, you can just run them as normal JUnit tests. When you need Robolectric, you use the Robolectric test runner. The runner you use is what makes the difference.
You run them all as JUnit tests anyway, so your entire library tests out with one run.

Open source Web Application Test Automation tool

We are starting on a web application and thinking of TDD development. Can anyone please provide me a list of open source tools to automate our testing.
Thanks in advance
Kaushik
First and the most important: Jenkins Continuous Integration Server (or a CI server from some other vendor).
You can also take a look at a list of CI servers in comparison.
There are also many other tools that ease the process of development using TDD such as:
Obviously Unit test frameworks (JUnit, TestNG)
Mocking frameworks (EasyMock, Mockito, PowerMock)
Also, don't forget Maven for building, Selenium for automating web app testing and JMeter for load testing.
Cheers,
Take a look at cucumber for BDD, it integrates with Jenkins and might help you with your acceptance tests.

testing a web application

I am a student and I have developed a web application based on JSP. Now my professor has suggested that i should do some tests like unit test etc for my web application.
Can anybody suggest what other test can I use to demonstrate the performance of my application.
And also any good resource from where I can study how to do unit testing, as I have never done any testing before.
Thanks!
Selenium is a popular framework for client-side unit tests (i.e. automating client input on a web page). The site also has a lot of introductory material.
For testing the server-side stuff the good, old JUnit will suffice - it's integrated in all major IDEs.
You should look into Kent Beck's Test-driven Development, although Test-Driven development is more than regular unit testing, this book will enlighten you (I bet) and you will write way better unit tests, too.
Selenium http://seleniumhq.org/
You should do unit testing for individual backing beans, an behavioural testing with something like Fitnesse
What you're talking about is "integration testing."
"Unit testing" is for proving the correct operation of individual components.
You can use SOAP UI to test SOAP-based web services.
You can automate testing of HTML user interfaces using Selenium UI.
Use JUnit for unit testing Java components, NUnit for .NET, etc.

coverage java tool

I'm wrintting java tests to control the GUI application, and I'm searching a tool to cover the java test , what is your recommandation ?
which tool is usually used to cover java tests ?
I recommend Cobertura for measuring test coverage. You can plug it into ant, maven, hudson, eclipse etc.
I recommend Sonar, see the hyperlink for how it shows code coverage (apart from doing many other handy things).
You can try to use Cobertura, it creates nice reports, and is easy to use in conjunction with junit, using ant or maven.
A great tool for reporting is Sonar, which integrates coverage tests, but also tools like checkstyle, findbugs, and provides a nice interface to analyse the outputs. It is also very easy to setup, definitively worth trying.
I strongly recommend taking a look at Code Pro tools. It's for Eclipse. And it contains a lot more than code coverage, it is code analyzer, junit test generator, dependency analyzer and so on...

How do you unit test Java EE code?

I want to ask for your prefered way to test Java EE code?
I found only three project, that are trying to help to code unit tests in Java EE environment:
http://jakarta.apache.org/cactus/ : Last Published: 2009-01-18
http://www.junitee.org/ : Last Release: 2004-12-11
http://ejb3unit.sourceforge.net/ : Last Release: 2008-05-17
So I wonder,
is there any framework helping to write (j) unit test for Java EE code?
do you use embedded Java EE servers like jboss or glassfish v3?
do you mockup and inject by yourself?
Thanks a lot...
If by Unit Testing you mean... unit testing (testing a unit in isolation), then you actually don't need any particular framework since EJB3.0 are nothing more than annotated POJOs and thus can be relatively easily tested without any special fixture.
Now, if you mean something else - like Integration Testing or Functional Testing - then, yes, tools can help and simplify things (but you should really start to use the right terminology :) I'll assume that this is what you have in mind.
First, JUnitEE seems dead and obsolete and I'm not even sure it has anything for EJB3.x. Second, I'm not impressed by the Java EE 5 support of Cactus and having to deploy Cactus tests is painful (I think that Cactus was nice for J2EE 1.4 but is a bit outdated now). So this leaves us with Ejb3Unit which is in my opinion the best option, especially if you want to run out of container tests i.e. without really deploying the application (much faster).
If you want to run in container tests, then you could indeed use an embedded container and my current preference goes to GlassFish v3, even for Java EE 5 (I may be wrong but I'm pretty disappointed by the starting time of the latest JBoss releases so it isn't getting much of my attention). See the post GlassFish Embedded Reloaded, an appserver in your pocket for sample code (that you could use from your tests) or Using maven plugin for v3 embedded glassfish (if you are using maven).
Another option would be to package and deploy your application with Cargo and then run some tests against the deployed application (with Selenium or a BDD tool for example). This could be useful if you want to run end-to-end tests with a container that doesn't provide any embedded API.
So, to answer your last question, I would indeed use available tools, maybe a combination of them, for tests that are not unit tests and wouldn't mock/inject stuff myself, except if they don't cover some needs that I can't think of right now.
As you are interested in unit testing, I recommend JUnit. You can unit test the methods in the core classes. If you have difficulty in writing unit test cases using JUnit, then probably the design is not modular and it is highly coupled. First focus on your core functionality and test it using JUnit.
I've been facing the same problem of running integration tests based on JUnit in a Java EE 6 container (Glassfish v3, to be precise), and after a lot of browsing and searching, I could not find a solution that really suited me needs, so I wrote my own, now published as jeeunit on Google Code.
I wouldn't call it a test framework, it is really just a handful of classes providing the glue between JUnit and Embedded Glassfish.
The general idea is similar to Cactus, your tests run in the container and get triggered by a servlet from outside.
jeeunit supports JUnit 4, Glassfish v3, CDI and generates the standard XML JUnit reports just like Ant or Maven Surefire (in fact, I reused some code from Ant for generating the reports).
I had a requirement to test a CDI application and wrote a custom JUnit runner that runs everything outside of the web container.
http://jglue.org/cdi-unit/
It is suitable for Java SE and also supports dummy Request, Session and Conversation scopes for testing web apps.
It's small and fast, which is great when you have lots of unit tests.

Categories

Resources