You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Bob Morley <rm...@emforium.com> on 2010/04/08 01:33:03 UTC

Renaming of java junit tests

Would anyone object if I renamed the junit tests if the Ofbiz project (and
related testdef)?  I believe the standard for a test fixture in JUnit is to
name the class <ClassName>Test (as opposed to Tests) and each test method in
that class would be named testXYZ.

Ofbiz follows the method naming convention, but it appears we have named a
number of junit tests with the plural "Tests" at the end.

Why is this important?  Some tools rely on these naming conventions to
determine which are tests and which are not.  I am doing some work in this
area and what I wanted to be able to do is execute JUnit tests from with-in
Eclipse getting all of the IDE candy associated with that.  From the
command-line we generate great code coverage metrics with Cobertura but
being pretty heavy into the Atlassian tool suite, I tend to use Clover when
running inside Eclipse.  By using the standard naming conventions, these
tools pickup the unit tests properly and make developing Ofbiz in Eclipse
even nicer (without any impact to the project).

Anyone have any Cons to doing this?
-- 
View this message in context: http://n4.nabble.com/Renaming-of-java-junit-tests-tp1755800p1755800.html
Sent from the OFBiz - Dev mailing list archive at Nabble.com.

Re: Renaming of java junit tests

Posted by Robert Morley <rm...@emforium.com>.
On Apr 8, 2010, at 6:08 AM, Erwan de FERRIERES wrote:

> the only thing I see with the tests, is that test files should not  
> be at the same directory level as the source code.
>
> I think that we should have :
> <component>/src/test
> and not :
> <component>/src/org/ofbiz/<component>/test
>
> the only point in this change, is when doing code coverage, it's  
> looking for coverage on the tests, which is not the best idea.
>
> But maybe someone with more knowledge would be able to tell if I'm  
> right or not...
>
> For naming the tests, the only thing we need with JUnit 3.8, is to  
> have the test prefixed with test. It's true for minilang tests as  
> well.

I remember having a discussion with someone based on that folder  
structure for tests; having come from a place where we did just that I  
was now in a place where they saw benefit in keeping the testing code  
in close proximity to the source code it is testing.  I just took a  
look at a few other projects in Apache to see what they have done ...  
what I typically found was that they follow this folder structure as  
well and they typically name their test classes "TestXXX".

Me thinks if we are going to spend anytime reorganizing our unit tests  
and establishing an Ofbiz best practice, we probably should just agree  
on it before I do anything.  Here is the only real information I could  
find from old trusty google ...

"JUnit 3.8 suggests the following naming conventions:

Test Case Class: Named as [classname]Test.java, where "classname" is  
the name of the class that is being tested. A test case class define  
the fixture to run multiple tests. A test case class must be subclass  
of junit.framework.TestCase.

Test Method: Named test[XXX], where "XXX" is any unique name for this  
test. A test method name should be prefixed with "test" to allow the  
TestSuite class to extract it automatically. A test method must be  
declared as "public".

Test Suite: Can be named any way you want to. But Eclipse uses  
AllTests.java as the name. A test suite is a collection of test cases."

The proposal I put forth is as such --

1) Move the junit test source into a folder structure as indicated by  
Erwan
2) Rename the test classes to follow the JUnit 3.8 naming convention  
above
3) Start separate discussion on splitting our "build" target into  
"compile" and "compile-tests" ensuring that test code is not included  
in the standard ofbiz application jar (ie. ofbiz-party.jar becomes  
ofbiz-party.jar and ofbiz-party-test.jar or something similar).


Re: Renaming of java junit tests

Posted by Erwan de FERRIERES <er...@nereide.fr>.
Le 08/04/2010 01:33, Bob Morley a écrit :
>
> Would anyone object if I renamed the junit tests if the Ofbiz project (and
> related testdef)?  I believe the standard for a test fixture in JUnit is to
> name the class<ClassName>Test (as opposed to Tests) and each test method in
> that class would be named testXYZ.
>
> Ofbiz follows the method naming convention, but it appears we have named a
> number of junit tests with the plural "Tests" at the end.
>
> Why is this important?  Some tools rely on these naming conventions to
> determine which are tests and which are not.  I am doing some work in this
> area and what I wanted to be able to do is execute JUnit tests from with-in
> Eclipse getting all of the IDE candy associated with that.  From the
> command-line we generate great code coverage metrics with Cobertura but
> being pretty heavy into the Atlassian tool suite, I tend to use Clover when
> running inside Eclipse.  By using the standard naming conventions, these
> tools pickup the unit tests properly and make developing Ofbiz in Eclipse
> even nicer (without any impact to the project).
>
> Anyone have any Cons to doing this?
Hi Bob,

the only thing I see with the tests, is that test files should not be at 
the same directory level as the source code.

I think that we should have :
<component>/src/test
and not :
<component>/src/org/ofbiz/<component>/test

the only point in this change, is when doing code coverage, it's looking 
for coverage on the tests, which is not the best idea.

But maybe someone with more knowledge would be able to tell if I'm right 
or not...

For naming the tests, the only thing we need with JUnit 3.8, is to have 
the test prefixed with test. It's true for minilang tests as well.

Cheers,

-- 
Erwan de FERRIERES
www.nereide.biz

Re: Renaming of java junit tests

Posted by Scott Gray <sc...@hotwaxmedia.com>.
On 7/04/2010, at 7:59 PM, Bob Morley wrote:

> Scott Gray-2 wrote:
>> 
>> OFBiz follows the textXXX method names because it has to for JUnit to work
>> (at least for the version we have).  Renaming the Class just seems like a
>> pain especially when a plural makes more sense.  Are you sure Clover isn't
>> configurable in this regard?
>> 
> 
> There is "Advanced Test Case Detection" that is typically used if you are
> using a framework other than JUnit 3.x, 4.x, or TestNG.  I could certain use
> that in my development environment and avoid the renames.  My line of
> thinking goes something like ... if there is a broadly accepted standard we
> should probably just adhere to it unless there is significant reason not to.
> 
> PROS: Adheres to broadly accepted naming convention, allows IDE tooling to
> pickup without additional configuration.

Well if it's a broadly accepted standard then I guess we should follow it.

> CONS: I suspect we lose SVN history, involves some work, if we upgrade to
> JUnit 4.x and use annotations there is less of a need (but I still think the
> naming conventions are a good thing).

You don't lose svn history when a file is renamed (so long as it is done properly but isn't difficult)

So yeah sure, I don't have a problem with making the change.  Anything that improves the tests is good with me.

Regards
Scott

Re: Renaming of java junit tests

Posted by Bob Morley <rm...@emforium.com>.

Scott Gray-2 wrote:
> 
> OFBiz follows the textXXX method names because it has to for JUnit to work
> (at least for the version we have).  Renaming the Class just seems like a
> pain especially when a plural makes more sense.  Are you sure Clover isn't
> configurable in this regard?
> 

There is "Advanced Test Case Detection" that is typically used if you are
using a framework other than JUnit 3.x, 4.x, or TestNG.  I could certain use
that in my development environment and avoid the renames.  My line of
thinking goes something like ... if there is a broadly accepted standard we
should probably just adhere to it unless there is significant reason not to.

PROS: Adheres to broadly accepted naming convention, allows IDE tooling to
pickup without additional configuration.

CONS: I suspect we lose SVN history, involves some work, if we upgrade to
JUnit 4.x and use annotations there is less of a need (but I still think the
naming conventions are a good thing).
-- 
View this message in context: http://n4.nabble.com/Renaming-of-java-junit-tests-tp1755800p1755899.html
Sent from the OFBiz - Dev mailing list archive at Nabble.com.

Re: Renaming of java junit tests

Posted by Scott Gray <sc...@hotwaxmedia.com>.
On 7/04/2010, at 5:33 PM, Bob Morley wrote:

> 
> Would anyone object if I renamed the junit tests if the Ofbiz project (and
> related testdef)?  I believe the standard for a test fixture in JUnit is to
> name the class <ClassName>Test (as opposed to Tests) and each test method in
> that class would be named testXYZ.
> 
> Ofbiz follows the method naming convention, but it appears we have named a
> number of junit tests with the plural "Tests" at the end.
> 
> Why is this important?  Some tools rely on these naming conventions to
> determine which are tests and which are not.  I am doing some work in this
> area and what I wanted to be able to do is execute JUnit tests from with-in
> Eclipse getting all of the IDE candy associated with that.  From the
> command-line we generate great code coverage metrics with Cobertura but
> being pretty heavy into the Atlassian tool suite, I tend to use Clover when
> running inside Eclipse.  By using the standard naming conventions, these
> tools pickup the unit tests properly and make developing Ofbiz in Eclipse
> even nicer (without any impact to the project).
> 
> Anyone have any Cons to doing this?

OFBiz follows the textXXX method names because it has to for JUnit to work (at least for the version we have).  Renaming the Class just seems like a pain especially when a plural makes more sense.  Are you sure Clover isn't configurable in this regard?

That said, I don't really care what they're called so long as they pass.

Regards
Scott