Bug 483424 - [JUnit][code templates] Templates for "before" and "after" test methods
Summary: [JUnit][code templates] Templates for "before" and "after" test methods
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5.1   Edit
Hardware: PC Windows NT
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-01 21:19 EST by Paul Benedict CLA
Modified: 2022-12-30 04:53 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Benedict CLA 2015-12-01 21:19:33 EST
There is a "test" template but I think Eclipse should also provide "before" and "after" templates for the typical setUp/tearDown case. Those are the default method names I chose in the template. Here are the templates I made and tested locally:

==
Name: before
Context: Java type members
Description: before test method (JUnit 4)

@${testType:newType(org.junit.Before)}
public void ${setUp}() {
	${cursor}
}

==
Name: after
Context: Java type members
Description: after test method (JUnit 4)

@${testType:newType(org.junit.After)}
public void ${tearDown}() {
	${cursor}
}

PS: Code body is indented with a tab; not spaces.
Comment 1 Noopur Gupta CLA 2015-12-18 10:35:56 EST
> We will not add @After and @Before templates, since the New JUnit Test Case 
> wizard can generate them when desired.

See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=395962#c11
Comment 2 Paul Benedict CLA 2015-12-18 10:47:43 EST
Except the wizard is when creating the class, right? You can have multiple before and after methods with JUnit 4 so that's the reason to add these templates. It's not good enough just to have one (literally one) created with the class; developers can have as many of these as wanted. I get tired of typing the before/after pattern when I require multiple; please reconsider your justification.
Comment 3 Pierre-Yves Bigourdan CLA 2018-12-20 17:30:27 EST
As Paul stated, multiple @Before and @After methods can be added to a test class. Also, I generally only need them when the tested class starts growing in complexity. Therefore, I often add them at a later point, not when I create the test class, which I presume would be the case for a lot of developers who practice TDD.

I wrote my own templates to deal with this, I would be happy to contribute them back to the project if there is a change of mind on this topic.
Comment 4 Eclipse Genie CLA 2020-12-10 01:20:40 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 5 Eclipse Genie CLA 2022-12-30 04:53:53 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.