[
https://issues.apache.org/jira/browse/SSHD-764?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Work on SSHD-764 started by Goldstein Lyor.
-------------------------------------------
> 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
> Labels: junit
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> 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)