[MAGNOLIA-3575] Support jUnit 4 in info.magnolia.test.TestUtil#getCurrentTestMethodName Created: 02/Mar/11  Updated: 07/Nov/14  Resolved: 06/Nov/14

Status: Closed
Project: Magnolia
Component/s: testing
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor
Reporter: Magnolia International Assignee: Daniel Lipp
Resolution: Won't Fix Votes: 0
Labels: quickwin
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File MAGNOLIA-3575.patch    
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:

 Description   

Here's a patch that should allow this (pending classloader issues - to be validated with tests running in forked mode)

The method - before and after patch - can appear a little unnecessary. In a regular junit3 test, one can simply do getName() to get the test method name. In Junit4, one can add the following to her test class

    @Rule
    public final TestName testName = new TestName();

and consequently do testName.getMethodName() when necessary.

However the util method allows to know the current test method in "external" classes (i.e where we'd have additional assertFoo() type of methods).

Additionally, the patch provides a desc() method, which can be used to provide a default assertion description (assertTrue(desc(), some.boolean())), thus avoiding unnecessary typing/test description duplication.



 Comments   
Comment by Daniel Lipp [ 03/Nov/14 ]

There's a special Rule for retrieving the current test method name: http://junit-team.github.io/junit/javadoc/4.11/org/junit/rules/TestName.html

Hence I'd not adapt TestUtil#getCurrentTestMethodName but simply drop it (don't think we have to deprecate and keep for another few major versions as we're anyway on junit 4 since a long time).

Comment by Daniel Lipp [ 06/Nov/14 ]

No need to rewrite that method as JUnit 4 has a proper rule for it.

Generated at Mon Feb 12 03:47:46 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.