| By Murali Kashaboina, Geeth Narayanan | Article Rating: |
|
| September 1, 2007 05:00 AM EDT | Reads: |
25,682 |
Note that the 'getEmployeeInfo' method internally calls 'getConnectionFactory' method to get a reference to the actual connection factory. The 'getConnectionFactory' is a protected method, as shown below, and helps in making the bean testable.
protected ConnectionFactory getConnectionFactory() throws Exception {
Context context = new InitialContext();
return (ConnectionFactory) context.lookup
(connectionFactoryJNDIName);
}
Running JUnit Tests Using Maven
We'll create a JUnit test case for 'GetEmployeeInfoBeanTest' under the 'src/test/java' directory with one 'testGetEmployeeInfo' test method as shown below:
public class GetEmployeeInfoBeanTest extends TestCase {
public void testGetEmployeeInfo() throws Exception {
String employeeId = "1000";
GetEmployeeInfoBean employeeInfoBean = new GetEmployeeInfoBean() {
protected ConnectionFactory getConnectionFactory() throws Exception {
EmployeeInfoSPIManagedConnectionFactory managedConnectionFactory = new
EmployeeInfoSPIManagedConnectionFactory();
return (ConnectionFactory)managedConnectionFactory.createConnectionFactory();
}
};
Employee employee = employeeInfoBean.getEmployeeInfo(employeeId);
assertNotNull( employee );
assertTrue( employee.getId().equals(employeeId) );
}
}
To run the test cases using Maven, right-click on the module's POM file in Eclipse and then in 'Run As' options, select 'Maven2 test.' Maven will compile the Java files found in 'src/test/java' and execute JUnit test cases. The result of test case execution can be found in the console.
Skipping Maven Test Execution
Maven will execute
test cases whenever a 'test' phase or any other phase that occurs after
a 'test' phase in the Maven lifecycle management is invoked. For
example, Maven will execute test cases when a Maven 'package' or
'install' phase is invoked. Maven does this by triggering 'maven-surefire-plugin' mojo at the time of the 'test' phase. This plug-in is responsible for executing the JUnit test cases found in the 'test-classes' directory in the project target build directory.
Test case execution can be explicitly skipped for compelling reasons. There are a couple of ways to make Maven skip test execution. One way is to explicitly include 'maven-surefire-plugin' in the POM file and set the value of the 'skip' configuration element to 'true' as shown here:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
If Maven is executed at the command line, test case execution can be skipped by setting the 'maven.test.skip' system property to 'true' as shown below:
mvn -Dmaven.test.skip=true install
Test cases can also be selectively skipped. This can be done by including 'maven-surefire-plugin' in the POM and explicitly specifying test classes using wildcard patterns in the 'excludes' configuration element as shown in the following snippet:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*FunctionTest.java</exclude>
</excludes>
</configuration>
</plugin>
For more information on 'maven-surefire-plugin,' see the plug-in documentation at http://maven.apache.org/plugins/maven-surefire-plugin/index.html.
Reporting Source Code Test Coverage Using Maven
Code coverage is a measure of how thoroughly test cases exercise the
main application source code. This is an indirect way of measuring the
quality of the tests. Code coverage is a type of white-box testing as
logical test assertions are made against the internals of our classes
and not against other subsystems or components the current application
may interact with. Code coverage helps to isolate logical paths in the
source code that aren't exercised under the test.
There are many tools to measure code coverage. Cobertura is an open source tool that can be used to measure test coverage. Cobertura instruments the code base and tracks lines of code that are being executed and lines that aren't being executed as the test suite runs. Besides identifying untested code, Cobertura can also optimize code by flagging dead and unreachable code. Cobertura has a Maven plug-in that can be configured in the POM. The plug-in has a set of goals that can be invoked separately. For more information on Cobertura Maven plug-ins, refer to plug-in documentation at http://maven-plugins.sourceforge.net/maven-cobertura-plugin/. We'll add the following plug-in configuration to the 'ejb' module POM.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<goals>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
Published September 1, 2007 Reads 25,682
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Murali Kashaboina
Murali Kashaboina is a lead architect at Ecommerce Technology, United Airlines, Inc. He has more than 10 years of enterprise software development experience utilizing a broad range of technologies, including JEE, CORBA, Tuxedo, and Web services. Murali previously published articles in WLDJ and SilverStream Developer Center. He has master’s degree in mechanical engineering from the University of Dayton, Ohio.
More Stories By Geeth Narayanan
Geeth Narayanan is a senior architect at Ecommerce Technology, United Airlines, Inc. He has 10 years of experience in the IT industry, specializing in solutions using Java EE technologies. Geeth has master's degree in electrical engineering from the University of Toledo, Ohio.
![]() |
Aladin SOHAILI 10/06/07 04:38:08 PM EDT | |||
Any link to download source files ? |
||||
![]() |
Bob Arnold 09/11/07 02:34:39 PM EDT | |||
Regarding: "It's time to add connector implementation Java classes. The source files that we developed for the connector are shown in Figure 4. Please specify the download link for the source code referred to. |
||||
![]() |
vinny 09/04/07 08:40:13 AM EDT | |||
Where is the link to download source files for connector EmployeeInfoCCIConnection?? |
||||
![]() |
Magne 09/04/07 03:25:58 AM EDT | |||
It was with great interest I read these articles. -magne |
||||
![]() |
Duty Editor 08/31/07 01:16:44 PM EDT | |||
The Links to Parts I and II are to be found at the foot of the final page. -Duty Editor |
||||
![]() |
Jim 08/31/07 11:51:57 AM EDT | |||
Next time you write part 3 of a three-part series, please include clickable links to the first two parts right there at the top. |
||||
- Kindle 2 vs Nook
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Windows 7 – Microsoft’s First Step to the Cloud
- Ulitzer Provides a Powerful Social Journalism Platform
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Open Source Mobile Cloud Sync and Push Email
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- US Post Office Hops a Ride on NetSuite’s Cloud
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Building a Drag-and-Drop Shopping Cart with AJAX
- What Is AJAX?
- Google Maps! AJAX-Style Web Development Using ASP.NET
- Flashback to January 2006: Exclusive SYS-CON.TV Interviews on "OpenAjax Alliance" Announcement
- AJAXWorld Conference & Expo to Take Place October 2-4, 2006, at the Santa Clara Convention Center, California
- AJAX Sponsor Webcasts Are Now Available at AJAXWorld Website
- How and Why AJAX, Not Java, Became the Favored Technology for Rich Internet Applications
- "Real-World AJAX" One-Day Seminar Arrives in Silicon Valley
- AJAXWorld University Announces AJAX Developer Bootcamp
- AJAX Support In JadeLiquid WebRenderer v3.1
- Where Are RIA Technologies Headed in 2008?
- Struts Validations Framework Using AJAX







































