W
W
web_dev2012-12-02 17:28:15
Java
web_dev, 2012-12-02 17:28:15

Testing a Java EE application?

Hello,

please tell me in more detail, I did some digging in Google, but there are a lot of things ...

There is a Java web-project [Spring, JPA, Hibernate, Vaadin].

How to write tests for such a project?
TestNG, JUnit?

Maybe someone will share a link or tell you where the simplest example of testing such a project is considered. (zhel in Russian)
Well, or briefly explain.

Thank you!

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
MrMig, 2012-12-02
@MrMig

There are several types of tests. If you are a backend developer, then you will be primarily interested in two types:

  1. Unit tests
  2. Integration tests

Unit tests are tests aimed at testing individual parts of a class. Most often these are methods. Sometimes - separate branches of methods (always true for god objects).
The most important point: for unit testing, you do not need to raise the application context! You are testing the logic of a single unit, not a bunch of classes. Therefore, very often I use mock frameworks for unit testing (as an example - mockito ). This is necessary in order not to write by hand - stubs of related classes.
What is covered by unit tests? Cover the business logic first (services, manager classes). Then there are the controllers. You can cover the DAO layer (again, if there is complex logic)0.
How to write a unit test?You take a set of input parameters, mock the dependency classes, pass the input parameters to the method under test, and test the output parameters. If the method has conditions, you need to get into all branches.
Should I write a separate test method for each branch? It depends on your style and whether you plan to refactor in the near future. In a good way, it is worth highlighting separate large branches in separate methods, especially for god objects.
Integration tests are the testing of multiple related classes. For example, business logic class + DAO class.
In the case of an integration test, you will have to raise the application context (usually separate configuration files are created for this). In addition, it would be nice to set up transactionalat the level of individual methods (in order not to clean the database with your hands after changes).
Need more details - write :)

A
Alex42rus, 2012-12-02
@Alex42rus

We have the same technology stack.
We use normal unit tests + selenium for GUI testing

W
web_dev, 2012-12-02
@web_dev

I would also appreciate an answer from my comment on Alex42rus 's answer .

A
Arktos, 2012-12-02
@Arktos

Integration tests with Maven, JUnit and Spring

R
relgames, 2012-12-04
@relgames

In my last job, we did unit and integration tests. For unit tests, we used TestNG, for integration tests, we wrote our own framework that emulated everything. The base was created in memory.
We use JUnit at a new job and are going to transfer integration tests to an in-memory base.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question