What is Pattern Testing?
[ vmassol ] 08:50, Wednesday, 21 April 2004

Pattern Testing is the concept of automatically verifying the good application of architectural/design patterns in code. It uses AOP to perform this feat.

Pattern Testing is a concept I started researching in 2002 on a big project at work. At that time, I was already using Checkstyle and PMD to perform verification of rules. However, I was finding them limited in several ways:

  • They were mostly focusing on syntactic rules, whereas I was mostly interested in semantic rule checking. Checkstyle has improved a lot in this area over the past 2 years. However, even though there are some semantic rules , they are usually simple and not very "business"-oriented. Note that this is not to diminish Checkstyle which I find great and use on all projects.
  • They were focusing on applying rules on a single file (using AST trees), whereas I was interested in applying rules that span several files (this is necessary for architectural/design checks). As a consequence writing pattern tests using Checkstyle is difficult.
  • They were limited to static checks. I wanted to be able to say "ensure that no method call is passed a null parameter", "ensure that there are no more than 10 calls to the database per user case", etc

The result was the Pattern Testing project on SourceForge. It's implemented using AspectJ. It contains some pre-made Pattern Tests but more importantly it lets you write your own. There is Maven plugin that makes it easy to run any Pattern Test on any mavenized project.

The possibilities of Pattern Testing are endless.

Here's an example of a rule that says that we do not want to instantiate business classes (i.e. a class that extends BasicBC). That's because they are instantiated by factories/service managers:

public aspect NoNewOnFrmwkClassesPatternTest
{
     declare error: 
       call(com.some.package.BasicBC+.new(..)) : 
         "Do not instantiate a business class directly";
}      

I used Pattern Tests for some time on that project at work and then I changed job. I was still interested in the concept but with my other open source involvements I didn't take the time to work on it as much as I wanted. Thus it became a bit abandoned. However, these past weeks, I have found renewed interest in the concept for several reasons:

  • I was contacted by Matt Smith who was interested in taking the lead of the Pattern Testing project. I gladly handed this over to him and he's now the one driving the project
  • I have started working on Cactus2 and as the Cactus 2 architecture is based on AOP, the concepts are very close.
  • On the new project I am on, we're starting to want to automate our architectural/design checks and some teams have initiated using Pattern Tests.

Are any of you using Pattern Testing too?


Comments

Also see:

http://www.hammurapi.org

--Peter Cominsky, May 14, 2004 05:20 PM

I love this idea. And I think it's a great project.
I am a graduate student in China. This summer
I did some intern work in a small company.I have that programmers all like using their way to coding.And even if we have asked them to using some libraries developed by us .Many willn't using it. For example , they were asked to using a connnection pool developed by the company.But some people just directly connect the database .
some even used another connection pool in their code.

Problems like this are a lot .

Now I am begin to do my master thesis.

I am interested in the patterntest project. And I am going to do some research on it.

--xufengbing, December 7, 2004 11:38 AM

Hai,
this is siva,i am working in huawei technologies,i am fresher,working on checkstyle rule writing.there is one problem already u know,i.e;only my rules aplicable for one file.Bou i want to write the rules to check all files.
please reply for this.


thanks and regards
siva.

--siva, November 20, 2007 03:21 PM
Post a comment









Remember personal info?