Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for TestNG assertion conversion #26

Open
tommyk-gears opened this issue May 26, 2020 · 0 comments
Open

Basic support for TestNG assertion conversion #26

tommyk-gears opened this issue May 26, 2020 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@tommyk-gears
Copy link

Is your feature request related to a problem? Please describe.
When converting TestNG tests the argument order in org.testng.Assert#assertEquals does not match the argument order in org.junit.jupiter.api.Assertions. I.e. in TestNG the argument order is (actual, expected, [message]), but in JUnit5 the argument order is (expected, actual, [message]).

So there are two problems:

  1. The plugin tries to move the message argument from first to last, which is not needed at all if the original assertion uses TestNG assertions.
  2. The plugin does not swap order of actual and expected arguments, which leads to quite misleading error messages if the assertion fails.

Describe the solution you'd like
If the original assertEquals invocation references the org.testng.Assert class the plugin should:

  1. Not try to move the message to the last parameter (it is already there).
  2. Swap order of the first and second argument.
  3. Replace TestNG imports with corresponding JUnit5 imports

E.g. this test:

import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

public class ExampleTest {

	@Test
	void test() {
		assertEquals("actual", "expected");
		assertEquals("actual", "expected", "message");
	}
}

Should be converted to:

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ExampleTest {

	@Test
	void test() {
		assertEquals("expected", "actual");
		assertEquals("expected", "actual", "message");
	}
}

Note that the plugin currently does method matching on method name only, i.e. it does the conversion of all invocations of methods with name assertEquals, regardless of which class that declared the assertEquals method.

Describe alternatives you've considered

  • Manual argument reordering (extremely tedious for large code bases).
  • Building another plugin for TestNG -> JUnit5 conversion

Additional context
TestNG also has a org.testng.AssertJUnit. Invocations to that class should be treated just like invocations to JUnit4 Assert. I think this alread woks today (except that the import statement is not replaced).

I do understand that converting TestNG to JUnit5 might be a bit out of scope (given the plugin name), but I still wanted to suggest this feature. I would really appreciate your feedback on this suggestion, I should be able to contribute a PR shortly if you think the feature fits in your plugin.

@wlsc wlsc added enhancement New feature or request help wanted Extra attention is needed labels May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants