rewrite-testing-frameworks icon indicating copy to clipboard operation
rewrite-testing-frameworks copied to clipboard

ParameterizedRunnerToParameterized update to account for test class inheritance

Open pway99 opened this issue 4 years ago • 5 comments

Discovered while applying JUnit4To5Migration on Antlr

For tests classes that inherit from a superclass and have a constructor which invokes the superclass constructor:

  • compare super constructor parameters with the MethodSource parameters
  • modify super constructor if necessary
  • add init method to class and superclass if necessary

before:

public class BaseRuntimeTest {
        public BaseRuntimeTest(RuntimeTestDescriptor descriptor, RuntimeTestSupport delegate) {
		this.descriptor = descriptor;
		this.delegate = delegate;
	}
}
public class TestPerformance extends BaseRuntimeTest {
	public TestPerformance(RuntimeTestDescriptor descriptor) {
		super(descriptor,new BaseGoTest());
	}
}

after:

public class BaseRuntimeTest {
        public BaseRuntimeTest(RuntimeTestSupport delegate) {
		this.delegate = delegate;
	}

	public void initBaseRuntimeTest(RuntimeTestDescriptor descriptor){
		this.descriptor = descriptor;
	}
}
public class TestPerformance extends BaseRuntimeTest {

	public TestPerformance() {
		super(new BaseGoTest());
	}

	public void initTestPerformance(RuntimeTestDescriptor descriptor) {
		initBaseRuntimeTest(descriptor);
	}
}

e.g. Antlr4-TestPerformance

pway99 avatar Mar 24 '21 19:03 pway99

This requires https://github.com/openrewrite/rewrite/issues/150

sambsnyd avatar Jun 15 '21 21:06 sambsnyd

This has been kicking around since March and we haven't prioritized it. Once we implement openrewrite/rewrite#150 we can revisit issues like this.

sambsnyd avatar Jun 17 '21 23:06 sambsnyd

Re-Opening given that 7.17.0 has better JavaType information

pway99 avatar Jan 11 '22 23:01 pway99

The current recipe implementation replaces the constructor with the initialize method. Applying this logic to the BaseTest and deleting the constructor may conflict with other usages. This could lead to failing migrations or builds.

MBoegers avatar Jun 18 '24 13:06 MBoegers

I've implemented a test case to reproduce in ParameterizedRunnerToParameterizedTest and implemented a first version of the required changes in the test methods. Currently the migration of the base class is missing.

MBoegers avatar Jun 22 '24 13:06 MBoegers