2

Just wondering if there are tools or plugins which provide an opportunity to surround an existing bunch of assertEquals() with assertAll()? Would like to make test code prettier but don't want to spend time for too much with manual typing...

Example

Imagine you have the following test code:

assertEquals("a", "a");
assertEquals("b", "b");
// ... n amount of assertions
assertEquals("c", "c");

In order to be up to date and to use benefits of assertAll you would like to change your code to this:

assertAll(
        () -> assertEquals("a", "a"),
        () -> assertEquals("b", "b"),
        // ... n amount of assertions
        () -> assertEquals("c", "c")
);

Currently, the only way to do this change is to rewrite this mannally with Ctrl+C, Ctrl+V and Ctrl+R maybe. However, I'm wondering if there are plugins or other tools for Intelij (for example) which allow you to surround you block of assertEquals with assertAll just by one click (@see InteliJ's "Code > Surround with..." window).

Actually this is a need when you work on a big project and which may have 10, 20 or 30 rows of assertEquals in a sequence. I wouldn't do this manually myself, this is dumb.

Why I ask this question? If there are no such solution I would like to create my own plugin for InteliJ which will provide this functionality.

Den
  • 53
  • 2
  • 8
  • Would it fail as long as one of the assertEquals failed ? – dreamcrash Dec 01 '20 at 10:12
  • No, and this is one of the benefits of assertAll. assertAll will go through all assertions even if some are failed. – Den Dec 01 '20 at 10:20
  • Please edit your question to show the code you would like to be able to write, and explain its desired behaviour – tgdavies Dec 01 '20 at 10:23
  • Does this answer your question? [assertAll vs multiple assertions in JUnit5](https://stackoverflow.com/questions/40796756/assertall-vs-multiple-assertions-in-junit5) – dreamcrash Dec 01 '20 at 10:25
  • @dreamcrash no, please see the updated version of this question. I've added example for a better explanation. – Den Dec 01 '20 at 10:43
  • Don't ask for "tools or plugins". Ask if it's possible. Please see [What topics can I ask about here?](https://stackoverflow.com/help/on-topic) – Scratte Dec 08 '20 at 16:22

0 Answers0