When I use the Create Test feature of IntelliJ IDEA, it generates test cases with a throws Exception
clause, for example:
@Test public void testIsInteger() throws Exception { }
This annoys me a bit: I prefer to add the specific throws
clauses myself only when necessary.
That way I see at a glance what kind of exceptions might be thrown by each test case.
How can I change this behavior of IntelliJ to omit the throws
clause?
Or am I wrong to want this? The creators seem to think this default behavior is a good thing.
Press ⇧⌘T (macOS), or Ctrl+Shift+T (Windows/Linux), to create the new Test class (or navigate to an existing Test class).
On the Runner page, select Skip tests and click OK. IntelliJ IDEA de-activates the test goal under the Lifecycle node. The appropriate message notifying that tests are skipped is displayed in the Run tool window when you execute other goals.
You can go into Settings/File and Code Templates/Code tab and change the template for the JUnit test method (there are templates both for JUnit 3 and JUnit 4 test methods).
That should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With