You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Goldstein Lyor (JIRA)" <ji...@apache.org> on 2017/08/21 10:50:00 UTC
[jira] [Created] (SSHD-764) Override default jUnit tests runner so
as not to create a new instance for each executed test method
Goldstein Lyor created SSHD-764:
-----------------------------------
Summary: Override default jUnit tests runner so as not to create a new instance for each executed test method
Key: SSHD-764
URL: https://issues.apache.org/jira/browse/SSHD-764
Project: MINA SSHD
Issue Type: Improvement
Affects Versions: 1.7.0
Reporter: Goldstein Lyor
Assignee: Goldstein Lyor
The default tests runner (if not specified) is {{BlockJUnit4ClassRunner}} its default behavior is to create a new instance of the test class for *each executed test method*. This can be changed by deriving an {{ExtendedBlockJUnit4ClassRunner}} and overriding its _createTest_ method:
{code:java}
public class ExtendedBlockJUnit4ClassRunner {
private final AtomicReference<Pair<Class<?>, Object>> testHolder = new AtomicReference<>();
protected Object createTest() throws Exception {
Pair<Class<?>, Object> lastTest = testHolder.get();
Class<?> lastTestClass = (lastTest == null) ? null : lastTest.getLeft();
TestClass curTest = getTestClass():
Class<?> curTestClass = curTest.getJavaClass():
if (curTestClass == lastTestClass) {
return lastTest.getRight();
}
Object instance = curTest.getOnlyConstructor().newInstance();
testHolder.set(Pair.of(curTestClass, instance));
return instance;
}
{code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)