poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Burch <apa...@gagravarr.org>
Subject Re: junit3 / junit4
Date Fri, 06 Nov 2015 17:03:47 GMT
On Fri, 6 Nov 2015, Javen O'Neal wrote:
> We currently have unit tests written in a mixture of junit3
> (junit.framework.*) and junit4 (org.junit.*).
>
> It would make sense to write new unit tests in junit4 since it's:
> * more flexible (classes don't need to inherit from TestCase, leaving you
> free to have them inherit from some base class that applies to common
> interfaces (SS: HSSF/XSSF/SXSSF)
> * concise (fail(msg) instead of throw new AssertionRaisedException(msg), no
> need to maintain explicit test suites).

All makes sense to me

> I haven't managed to figure out the pattern on why some unit tests are
> written in junit3 and others are junit4. I presume it's the age of the
> test

Age, I believe. The project started having unit tests before Junit4 came 
out! On the whole, new tests since then have been written as junit 4 ones, 
and some tests upgraded, but many remain 3

> Looking forward, do we want to try to convert existing junit3 tests to 
> junit4 (this would also be a good opportunity to fix the plethora of 
> whitespace variations in unit tests)? If so, do we want to blitz through 
> this in a concentrated effort, or just upgrade junit tests as needed 
> when we need to add a test case to a junit3 file?

Unless you feel keen, I'd say just upgrade when you touch a file.

> For the sed/awk/emacs gurus out there, is there a more time efficient 
> way of converting junit3 tests to junit4 other than manually opening 
> each junit3 file, deleting the junit.framework, fixing all the red 
> errors reported by Eclipse, and annotating every "public void test" 
> method with @Test?

sed -i -e 's/public void test/@Test\n    public void /' -e 's/import 
junit.framework.TestCase/import org.junit.Test;\nimport static 
org.junit.Assert.*/' -e 's/ extends TestCase//' -e 's/public void 
setUp/@Before\n    public void setUp/' Test*.java

Add a few more "-e 's/old/new/'" commands as needed!

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message