Tuesday Jun 16, 2015

Create Test Logs Like Javadocs

In a new article, Madhu Seelam and Raghunandan Seshadri describe how to build a test framework that ensures logs from test classes and TestNG listeners that are executed in parallel reach the appropriate log file and are organized in a format similar to that of Javadocs.

TestNG is a popular open source test automation framework that provides support for parallel test execution. Java Logging APIs can ensure thread-safe logging from numerous threads and logging within test cases, as well as callback functions within listeners. However, when tests are executed in parallel, the logs from various test cases are interleaved, which makes it difficult to isolate the logs for a given test case.

Using the solution described in this article, all logs from a given TestNG test class reside in one HTML file, and HTML files can be linked into a format similar to that of Javadocs. This enables you to select a package and select the corresponding class to view the logs related to just that test class, even when the tests have been executed in parallel. Read the article

Wednesday Sep 07, 2011

Unit Testing for Java EE tech article on OTN

A new article, titled “Unit Testing for Java EE,” by Java Champion Adam Bien, is up on otn/java’s front page. Bien points out that too many developers believe that testing Java EE applications is too hard, inconvenient, or complex, something that has not been true since the advent of Java EE 5 more than five years ago.

Bien explains: “There is nothing special about unit testing Java EE 6 applications. You only have to add the JUnit library into your pom.xml file (see Listing 5) and put your classes into the src/test/java directory. All JUnit tests will be executed automatically during the standard Maven lifecycle: mvn clean install.”

He goes on to make use of “Mockito” an easy-to-use, open source mocking library. Bien writes:

“Mockito is able to create ‘smart proxies’ (a.k.a. mocks) from classes or interfaces. These proxies do not come with any behavior, but they are still perfectly usable. You can invoke methods, but will get the default values, or null, back. The behavior of the mocks can be recorded after their creation with when(mock.getAnswer()).then(42) syntax.

Mockito is perfectly suitable for ‘simulating’ any inconvenient classes, resources, or services. You can start with Mockito just by knowing a single class org.mockito.Mockito. The when-then ‘domain specific language’ is composed of static methods from the Mockito class. The org.mockito.Mockito class is well documented. In fact, the whole documentation set was generated from the JavaDoc markup in the org.mockito.Mockito class.”

Read the complete article here.

About

Insider News from the Java Team at Oracle!

duke
Links


Search

Archives
« July 2015
SunMonTueWedThuFriSat
   
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
       
Today