Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make IntelliJ generate tests without throws Exception

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.

like image 527
janos Avatar asked Nov 06 '14 09:11

janos


People also ask

How do I generate test cases automatically in IntelliJ?

Press ⇧⌘T (macOS), or Ctrl+Shift+T (Windows/Linux), to create the new Test class (or navigate to an existing Test class).

How do I exclude test cases in IntelliJ?

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.


1 Answers

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.

like image 184
Bohuslav Burghardt Avatar answered Sep 22 '22 19:09

Bohuslav Burghardt