Java Memory Profiling Simplified


As a typical Java developer I never monitored the memory usage of my application apart from following typical best practices like closing the connections, streams etc.. Recently we were struck with few issues in our JBoss servers that I had to dig in to the memory management. 

One of the best thing in java is that the developers are not required to handle the memory allocations when the objects are created. The JVM does that for us. Most of the time we just need the outer layer knowledge of heap memory and garbage collector. I will share some really interesting investigations that I had. I is a huge topic and I am writing from a point of view of a web application developer, what all minimum I thought we should understand about it.


The Tools


There are number of good tools available to profile the java applications some of them are,


1. Your Kit Java Profiler

2. JProfiler 
3. Eclipse MAT
4. Visual VM

Out of these Your Kit and JProfilers needs licences and others are free to use products. We are going to use VisualVM. It is a simple yet powerful tool and comes bundled inside the JDK. It has power list of plugins that you can download and use. To start using VisualVM, go to your <JDK_HOME>\bin and run the jvisualvm.exe. I found the below articles it useful to get going. 



1.Profiling With VisualVM
2.VisualVM performance tuning tool
3.How to Get VisualVM to Profile JBoss Without Crashing


Since we are talking about memory here make sure you install the Visual GC plugin on the VisualVM as told in this article.


Setting the stage - JVM Memory Structure


The JVM Memory is divided in to 3 parts as shown in the below image. In our applications we are concerned about the Heap Memory. We can input this value to JVM using the parameters,


-Xmx<size> - to set the maximum Java heap size
-Xms<size> - to set the initial Java heap size




JVM Memory Structure

The non-Heap memory stores per-class structures such as runtime constant pool, field and method data, and the code for methods and constructors, as well as interned Strings.

Here is a nice article with more details on the JVM memory sizes. Read Javin's article on JVM Heap space here. 

The one common confusion is about the stack memory and heap memory. This is well explained here.Stack values only exist within the scope of the function they are created in. Once it returns, they are discarded. Java only stores primitives on the stack. This keeps the stack small and helps keeping individual stack frames small, thus allowing more nested calls. Objects are created on the heap, and only references (which in turn are primitives) are passed around on the stack.

Now, Lets get real. Given below the image from Visual GC, a plugin inside the VisualVM as told earlier. We see many graphs here a detailed decription of the output is available here. 




The Game begins - What happens when the application runs

When the objects are created, they reside inside the Eden. When the Garbage collector(GC) runs, if the object is dead (means they are no active references) it is flushed out otherwise they are moved to S1(Survivor Space 1) or S2. This is called a GC cycle. Internal GM algorithm decides the frequency of the GC cycle. Eden + S1 + S2 section of Heap memory is called as Young generation. Objects that survives a fixed number of GC cycles are moved in to Old Gen space. Most number of java objects die as infant and never reach Old Gen. This typically includes local variables which are flushed after the methods are executed.

The frequency of GC cycles inside the Old Gen is much lesser than Young Gen. Typical examples of Old Gen objects are singletons, cached objects and other application wide used data.


When things do not go as per the plan

In a typical application there will be less variation inside the Old Gen space. If the Old Gen space grows linearly with time even after the GC cycle that would lead to a OutOfMemoryError. This might be a indication of a memory leak inside the code. However we might need to use a profiler to find out the exact reason for the same. Here is a Dzon article on some of the Causes of Java EE Enterprise Performance Problems.


These are the basic building blocks of how JVM memory is organized and reacts when the application is executed. From this point there are lots of topics including tuning the memory parameters and garbage collector. I will add some of the useful resources related to this.

1. Java Performance Tuning, Profiling, and Memory Management
2. InfoQ Presentation : Diagnosing Web Application OutOfMemoryErrors
3. InfoQ Presentation : Everything I Ever Learned about JVM Performance Tuning @twitter
4. InfoQ Presentation : Extreme Performance Java  
5. Java theory and practice: Garbage collection and performance
6. Understanding Java Garbage Collection


Update on 27 Sept 2013:


More on JVM Garbage Collection

Recently I have given a talk at Eclipse Day India event, I am adding the slides from the talk and details of the Demo here so that you can make use of it.

Steps for the Demo:
If you use eclipse and test the Visual GC plugin with some controlled load in the memory, download the plugin and put it under the "dropins" folder in eclipse. Restart your eclipse, you should be getting a new item in the Menu bar "Memory Tester". By clicking the Click on "Add Memory Load" you can load some objects in the memory and observe the behavior of Visual GC.




I have recently presented the content of this article and there are the slides!


All about Hibernate Second Level Cache



Recently I have experimented with hibernate cache. In this post I would like share my experience and point out some of the details of Hibernate Second Level Cache. On the way I will direct you to some articles that helped me implement the cache. Let's get started from the ground.


Caching in hibernate

Caching functionality is designed to reduces the amount of necessary database access. When the objects are cached they resides in memory. You have the flexibility to limit the usage of memory and store the items in disk storage.The implementation will depend on the underlying cache manager. There are various flavors of caching available, but is better to cache non-transactional and read-only data.

Hibernate provides 3 types of caching.


1. Session Cache

    The session cache caches object within the current session. It is enabled by default in Hibernate. Read more about Session Cache. Objects in the session cache resides in the same memory location.

2. Second Level Cache


     The second level cache is responsible for caching objects across sessions. When this is turned on, objects will be first searched in cache and if they are not found, a database query will be fired. Read here on how to implement Second Level Cache. Second level cache will be used when the objects are loaded using their primary key. This includes fetching of associations. In case of second level cache the objects are constructed and hence all of them will reside in different memory locations.

3. Query Cache


Query Cache is used to cache the results of a query. Read here on how to implement query cache.When the query cache is turned on, the results of the query are stored against the combination query and parameters. Every time the query is fired the cache manager  checks for the combination of parameters and query. If the results are found in the cache they are returned other wise a database transaction is initiated.  As you can see, it is not a good idea to cache a query if it has number of parameters or a single parameter can take number of values. For each of this combination the results are stored in the memory. This  can lead to extensive memory usage.

Finally, here is a list of good articles written on this topic, 

1. Speed Up Your Hibernate Applications with Second-Level Caching
2. Hibernate: Truly Understanding the Second-Level and Query Caches
3. EhCache Integration with Spring and Hibernate. Step by Step Tutorial
4. Configuring Ehcache with hibernate

Doing more as a Programmer


In this post I want to write about my first talk titled Doing more as a Programmer. This presentation is about maximizing your value as a programmer by enhancing the way you interact with yourself, your surroundings, with community and to your career.


I have attached the presentation here, it is available on SlideShare.
I had fun presenting it in my office, hope you will enjoy it too.

Why should you use Unchecked exceptions over Checked exceptions in Java



The debate over checked vs. unchecked exceptions goes way, way back. Some say it’s one of the best features Java included. Others say it was one of their biggest mistakes[1].

It looks like the debate is over. In this post I will try to include the links to articles and books which speaks about this topic. I am not an expert voice in this, but I will try to explain you why did I reach the this conclusion.

So, we are talking about,

Unchecked exceptions :
  • represent defects in the program (bugs) - often invalid arguments passed to a non-private method. To quote from The Java Programming Language, by Gosling, Arnold, and Holmes : "Unchecked runtime exceptions represent conditions that, generally speaking, reflect errors in your program's logic and cannot be reasonably recovered from at run time."
  • are subclasses of RuntimeException, and are usually implemented using IllegalArgumentException, NullPointerException, orIllegalStateException
  • a method is not obliged to establish a policy for the unchecked exceptions thrown by its implementation (and they almost always do not do so)
Checked exceptions :
  • represent invalid conditions in areas outside the immediate control of the program (invalid user input, database problems, network outages, absent files)
  • are subclasses of Exception
  • a method is obliged to establish a policy for all checked exceptions thrown by its implementation (either pass the checked exception further up the stack, or handle it somehow)
The above are as told in Java Practices Page[2].


In many of the projects I have worked on, I have seen different ways of coding and various different strategies, code formatting, class naming styles, databases and technologies. The one thing that remained same was, Exceptions. All the projects had custom exceptions, created by extending Exception class!

I am sure that most us of know the difference between checked and unchecked exceptions, but very few thinks carefully before using them. I wanted all the details to be listed in single page so that I could convince my team to switch to Unchecked  exceptions.

In his famous book, Clean code: a handbook of agile software craftsmanship[3], Robert C. Martin writes the below lines supporting Unchecked Exceptions.

The debate is over. For years Java programmers have debated over the benefits and liabilities of checked exceptions. When checked exceptions were introduced in the first version of Java, they seemed like a great idea. The signature of every method would list all of the exceptions that it could pass to its caller. Moreover, these exceptions were part of the type
of the method. Your code literally wouldn’t compile if the signature didn’t match what your code could do.

At the time, we thought that checked exceptions were a great idea; and yes, they can yield some benefit. However, it is clear now that they aren’t necessary for the production of robust software. C# doesn’t have checked exceptions, and despite valiant attempts, C++ doesn’t either. Neither do Python or Ruby. Yet it is possible to write robust software in all of these languages. Because that is the case, we have to decide—really—whether checked exceptions are worth their price.

Checked exceptions can sometimes be useful if you are writing a critical library: You must catch them. But in general application development the dependency costs outweigh the benefits

The last line is most significant, where he speaks about the general application  development, Lets take an example,


If you have to read an XML file using a DOM Parser, we need to deal with some checked exceptions[5] like ParserConfigurationException, SAXException and IOException . The API developer thought that if the XML was invalid, they should notify so that the consumer of the API(ie, the application developer) can decide how to handle the situations.

Now, If You have some alternatives to proceed with the normal logic, you could do that, other wise you should catch these checked exceptions and throw and Unchecked exception. This way the method signatures will be clean also, we are stating that if the XML is invalid we are can not do much, and we are stopping the processing. Let the error handler written at the top layer take the appropriate decision on what to do.

So, all we need to do is to create out custom exception class by extending RuntimeException.

In the Java Tutorial hosted by Oracle, there is an interesting page about this debate[4], the page ends with the line, If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.

I have also found few article supporting this,


The Tragedy Of Checked Exceptions by Howard Lewis Ship
Exceptions are Bad  by  Jed Wesley-Smith


Also, few articles on general exceptional best practices,


Guidelines Exception Handling By Vineet Reynolds
Exceptional practices  By Brian Goetz

Useful Eclipse Plugins that didn't make it to the Top 10 list



Eclipse IDE project is started aiming to provide a universal tool set for development. Open Source IDE, mostly provided in Java, but the development language is independent. Eclipse market place hosts the list of plugins for the worlds most popular IDE. You can see the Top MPC Downloads and Top Favorites plugins are highlighted in the site. In this post I will introduce you some of the coolest eclipse plugins that I have used but were not part of the Top 10 list shown in the marketplace.

Below are my favorite plugins which are already listed in the top 10 list.

1. Spring Tool Suite
2. Maven Integration for Eclipse
3. Subclipse
4. UMLet
5. FindBugs
6. CheckStyle
7. AnyEdit

Givern below the ones that don't made it to the top 10 list but can make it one day!

General Purpose Tools

1. Rabbit

Rabbit is a time tracking plug-in for Eclipse. It runs silently in the background to record how you spend your time within Eclipse and reports the data back to you whenever you want it to - in a useful way.

2. InstaSearch

InstaSearch is an Eclipse plug-in for doing fast text search in the workspace. The search is performed instantly as-you-type and resulting files are displayed in an Eclipse view. It is a lightweight plug-in based on Apache Lucene search engine. Each file then can be previewed using few most matching and relevant lines. A double-click on the match leads to the matching line in the file.

3. EasyShell

This plugin allows to open a shell window or file manager from the popup menu in the navigation tree or editor view. The current directory of the opened shell is the directory which was selected with the popup menu. Additionally it is possible to run selected file in the shell and copy file or directory path. Multiple selections are also supported.

4. Eclipse Todo Editor

Manage your todos in an easy to use text editor with syntax highlighting and code completion. Effectively structure and query your todo lists using projects and custom tags. 

5. MailSnag

With MailSnag, you can debug application generated emails within Eclipse. MailSnag creates a simple SMTP server to capture and inspect emails sent out by an application during development. You can view the email rendered as HTML, text or both. You can also view the raw data, embedded content and attachments.

6. More Clipboard

More Clipboard keeps track of the latest entries copied/cut into clipboard buffer and allows quick pasting from the popup list by pressing a hotkey. Inspired by Multi Clipboard plugin for Eclipse and Visual Assist for MS VS.

7. ObjectAid UML Explorer 

The ObjectAid UML Explorer is optimized for the quick and easy creation of UML class and sequence diagrams from existing Java source code and libraries. It uses the UML notation to show a graphical representation of existing code that is as accurate and up-to-date as your text editor.

8. AgileReview

AgileReview provides you with an easy possibility to do code reviews in your favorite IDE. Code reviews are a powerful meaning for quality assurance, but switching between spreadsheets and code is very time consuming. With AgileReview you can comment and discuss code without leaving the IDE and more important: without leaving the code.


Tools for Java Developers

9. JAutodoc

JAutodoc is an Eclipse Plugin for automatically adding Javadoc and file headers to your source code. It optionally generates initial comments from element name by using Velocity templates for Javadoc and file headers.

10. JadClipse

 If you use JadClipse the Class File Viewer will be replaced with the JadClipse Class File Viewer that shows the decompiled source of the class. This task is accomplished by decompiling the corresponding class file in the background using Jad. Normal Java syntax highlighting as well as the Outline View are supported.

Unit Testing

11. JUnit Helper

"JUnit Helper" helps JUnit users to cover all tests for public, protected and package local methods by saving much labor to start writing new test cases. Eclipse plugin also has an advantage of making it easier to go back and forth between developing class and test class by "Alt + 8" (test->dev) and "Alt +9"(dev->test).

12. MoreUnit

MoreUnit is an eclipse plugin that should assist you writing more unit test. The following features are implemented: - Decorate classes which have a testcase. - Mark methods in the editor which are under test. - Jump to a testcase in the editor via the menu or a shortcut (and back) - Generate a testmethod stub for the method under cursor-position in the editor via the menu or a shortcut. - Rename/move of classes / methods with corresponding testcases automatically starts refactoring for tests as well.

Looging Helpers

13. Logging code Cleanup for Eclipse

Logging code Cleanup plugin for Eclipse is an extension of the Eclipse Cleaun Ups which detects invocations of logging methods with compound arguments (requiring computation before method call) and prefixes them with corresponding if statements.

14. Log4E

Log4E is an Eclipse Plugin which helps you to set up your logger easily in Java Projects. It assists you in several tasks: logger declaration, logger Insertions at certain method entries, substitution of System out's, modification of already existing logger statements. Log4E has active support for Log4j, Commons Logging and JDK 1.4 Logging. By defining your own templates you might be able to adapt your own logger to the Plugin. 

UML and Code Analysis Tools

15. ModelGoon UML4Java

ModelGoon brings new points of view of a Java project. Thanks to its tight connection and interaction with the Eclipse Java Development Tools JDT. ModelGoon provides also round-trip features on Class Diagrams actually as beta.

16. CodePro AnalytiX

CodePro AnalytiX is the premier Java software testing tool for Eclipse developers who want to be active participants in improving the quality and security of the code they produce. CodePro AnalytiX seamlessly integrates into the Eclipse environment, using automated source code analysis to pinpoint quality issues and security vulnerabilities before code reaches QA, or worse, production!

17. Sonar

Sonar for Eclipse provides comprehensive integration of Sonar into Eclipse. It shows quality issues while browsing the source code. Developers are made aware of quality issues compared to corporate standards without leaving their favorite IDE and thus enabling for continuous improvement with no effort. No propagation of standards changes is required anymore as definition is centralized.

18. MaintainJ

MaintainJ generates the runtime sequence diagrams for a use case. MaintainJ generated diagrams are dynamic, easy to explore and help Java developers to understand, debug and document Java applications.

19. EclEmma Java Code Coverage

EclEmma is a free Java code coverage tool for Eclipse, available under the Eclipse Public License. It brings code coverage analysis directly into the Eclipse workbench

20. eCobertura

eCobertura enables you to launch your applications or tests in Cobertura-covered mode directly from within Eclipse. View your source files colored according to the coverage results. Browse through the detailed coverage results in a tree view.

Note:- The numbering is arbitrary and does not imply the importance. The description about each plugins is copied from the Eclipse Market Place.

Upgrading Tapestry version from 5.0.18 to 5.2.5: Issues and Resolutions



In this post I am going to write about the issues that we have faced during the up-gradation of the tapestry version from 5.0.18 to 5.2.5 in one our projects. Below are some of them. Hope this collection will help someone!


1. Changes in the RequestPathOptimizer file inside tapestry.


Issue Logs:-


Caused by: java.lang.ClassNotFoundException: org.apache.tapestry5.internal.services.RequestPathOptimizer from BaseClassLoader@41c491{VFSClassLoaderPolicy@1d02b85{name=vfsfile:/D:/SVN/trunk/export/tools/jboss-5.0.1.GA/server/default/deploy/ROOT.war/ .......
at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:422)


Solution:-


Remove all the tapestry-spring dependancies to resolve this issue.


Reference:-


Tapestry JIRA 
Mailing list URL 




2.Including the tapestry bean validator jar.


Logs:-


Caused by: java.lang.ClassNotFoundException: javax.validation.ValidatorFactory from ......
..............
real=file:/D:/SVN/trunk/export/tools/jboss-5.0.1.GA/server/default/deploy/ROOT.war/WEB-INF/lib/XmlSchema-1.4.2.jar]] delegates=null exported=[]}} at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:422)


Solution:-


There is new feature in Tapestry called bean validator that needs the validation api and implementation jars to be added it can be downloaded from the project homepage here.


3.Changes in the tapestry spring integration.


Logs:-


Caused by: java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:179)
at org.apache.tapestry5.internal.spring.SpringModuleDef$3$1.invoke(SpringModuleDef.java:194)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:65)
... 91 more
java.lang.RuntimeException: Exception constructing service 'ApplicationContext': Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!


Solution:-


From Tapestry 5.2.x it will load the spring context automatically and hence we need to remove the below from web.xml. This will help in live class loading of service class. Also the spring beans should be wired and not to be injected as services.As per this there will be changes in All the Page classes and web.xml


Reference:-


Mailing list URL
Tapestry Wiki-1 
Tapestry Wiki-2


As per the article "The changes below represent an unfortunate backwards compatibility issue. If necessary, you can still use tapestry-spring version 5.0.18 with the rest of Tapestry."


If we want to continue using spring-tapestry 5.2.5 jar we have to make changes in each and every Page file where spring services are injected. Also the spring beans should be wired and not to be injected as services.




4. Using Tapestry 5.2.5 inside the JBoss Application server.


Logs:-


Caused by: java.io.IOException
at org.jboss.virtual.plugins.registry.DefaultVFSRegistry.getFile(DefaultVFSRegistry.java:125)
at org.jboss.virtual.protocol.AbstractVFSHandler.openConnection(AbstractVFSHandler.java:71)
at java.net.URL.openConnection(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at org.apache.tapestry5.ioc.internal.services.ClassNameLocatorImpl.scanDirStream(ClassNameLocatorImpl.java:182)
at org.apache.tapestry5.ioc.internal.services.ClassNameLocatorImpl.scanURL(ClassNameLocatorImpl.java:131)
at org.apache.tapestry5.ioc.internal.services.ClassNameLocatorImpl.findClassesWithinPath(ClassNameLocatorImpl.java:96)
at org.apache.tapestry5.ioc.internal.services.ClassNameLocatorImpl.locateClassNames(ClassNameLocatorImpl.java:75)
... 85 more
Caused by: java.net.URISyntaxException: Illegal character in path at index 159: vfszip:/D:/SVN/trunk/export/tools/jboss-5.0.1.GA/server/default/deploy/ROOT.war/WEB-INF/lib/tapestry-upload-5.2.5.jar/org/apache/tapestry5/upload/components/PK/
at java.net.URI$Parser.fail(Unknown Source)


Solution:-


As per the below links we need to use a patch to fix it.


Mailing list URL-1
Mailing list URL-2 
Tapestry JIRA
Tapestry Wiki



5. Changes in the Locale implementation


If you use the url to load pages and your application supports the multiple languages then you need to append the locale code infront of the url.


For example:
Current url: "http://localhost/superpopup" should be changed to "http://localhost/${localeInd}/superpopup" 


Mailing List URL  


6. Tapestry handling of transients instances ValueEncoder


Mailing List URL


7. Change in the way @Secure is handled in the page classes.


Most of the applications we will have the Index page tagged with the @Secure annotation to force the usage of https protocol. Some how I could not get this done with the existing settings. To have this you need to add the below lines.


configuration.add(SymbolConstants.SECURE_ENABLED, "true");


Mailing List URL


When to replace Unit Tests with Integration Test


Its been a while I was thinking about integration vs unit testing. Lots of googling, questions in stack overflow and looking in many books. In this post I would like share with you the information I have found and what decision I arrive at this.


I think if you put this question to any Java developer, you will get an anwser supporting the unit test instantaneously. They will tell you that if you can not do unit testing, the unit of code you hava written is large and you have to bring it down to multiple testable unit. I have found these questions in Stack Overflow 1, 2, 3 and 4 useful in getting a good understanding of both terminologies.

Unit testing is widly followed in Java domain with most of the projects now also enforcing the code coverage and unit testing. Integration testing is relativly new and misunderstood concept. Even through it is practiced much less than, unit testing there can be varios uses of it. Lets take a simple user story and revisit both.

Lets consider it with a user story

User will give an INPUT in a UI form and when the submit button is clicked, the PROCESSED output should be shown in the next page. Since the results should be editable, both INPUT and OUTPUT should be saved in the database.

Technical Design

Lets assume that our application will grow rapidly in the future and we will design it now keeping that in mind. 


As shown in the above image it is a standard 4-tier design with view, service, dao. It has a application layer which contains the logic of how to convert the input into output. To implement the story we wrote 5 methods(1 in service, 2 dao to save input and output, 1 contains the business and 1 method in view layer to prepare the input.)

Writing some Unit test cases

If we were to unit test the story, we need to write 5 tests. As the different layers are dependent, we might need to use mock objects for testing. But apart from one method in application layer that does the original process, is there any need to unit test the other part? For example the method,

 public void saveInput(Input input){  
           Session session = sessionFactory.getCurrentSession();  
           session.save(input);  
 }  


When you unit test this, you will typically use a mock object of sessionFactory and the code willl always work. Hence I don't see much point in wiring a unit test here. If you observe carefully, apart from the application layer, all the other methods will be similar to what we have discussed.


What can we acheive with integration test?


Read here as a heads up for the integration test. As we have seen most of the unit tests for this story were not effective. But we can't skip testing as we want to find out the code coverage and make our code self testing. According to Martin flower in his article about Continuous Integration you should write the code that can test the other code. I fell the good integration tests can do this for you.


Lets write a simple itegration test for this situation,

 @Configurable(autowire = Autowire.BY_NAME)   
 @RunWith(SpringJUnit4ClassRunner.class)   
 @ContextConfiguration(locations = {"classpath:applicationContext.xml"})  
 public class SampleIntTest {  
      @Autowired  
      private SamService samService;  
      @Test  
      public void testAppProcessing(){  
      Input input = new Input();  
      //prepare input for the testing.  
      Output output = samService.processInputs(input);  
      //validate outpt gainst the given input.  
      if(!isValidate(input,output)){  
           Assert.fail("Validation failed!");  
      }  
 }  



I have skipped the view layer here as it not so relevent. We are expecting the INPUT from the UI in a bean Input and thats that we willl have in the service layer. Here, With this few line of coding, you can acheive the full functionality of the application from the service layer.


It is prefered to use a in-memory database like H2 for integration tests. If the table structure is complicated it may not be possible in that case,you can use a test instance of DB and prepare a script to delete all the data and run it as part of the test so that the DB state is restored back. This is important because in the next run the same data will be saved again.


Another advantage of integration tets is that if you are changing the implementation the test need not be changed because it ic concerned with the input and output.This is useful in refactoring the code without change in the test code. Also, you can schedule these tets to measure the stability of the appication and any regression issues can be caught early.


As we have seen, integration test are easy to write and are useful, but we need to make sure it does not replace the unit testing completely. When ever there is a rule base system(like the LogicalProcesser in our case) it should be mandatory because you can't cover all the scenarios with the integration test.


So as always JEE is about making choice asnd sticking to it. For the last few months we were practicing it in our teams and it is really going well. Currently we made integration test mandatory and unit tests and optional. Always review the code coverage and make sure you get good coverage in the core of the system(the LogicalProcesser in our case).