I just bought a copy of Intellij and I need to generate a unit test stub and put junit on the classpath and set the test to execute with the junit runner. It's trivial to do so in Eclipse.
Every instruction I read looks like this...
But I do not want to create any class, or any Method until I have a Test that won't compile.
I want to layout the Class and method stubs first in a test. Once I am satisfied with the API I've expressed in the test I want to auto generate the Class and Method declarations, and then begin with the assertions.
How to do this in Intellij?
IntelliJ IDEA automatically detects Eclipse projects located on your computer and places them in the dedicated node right on the Welcome screen. This node will be available among the recent projects until you decide to remove it. When the Eclipse project is in the node, just click it to quickly open it in the IDE.
Right-click the test root folder or package in the test root folder in which you want to create a new test and select New | Java Class. Name the new class and press Enter . Press Alt+Insert and select Test Method to generate a new test method for this class. Name the new method and press Enter .
Create a test folder and add a new test class, for example WhateverTest.java
Add a new method that has an @Test
annotation.
@Test
public static void whatever() {
}
After you import all the required JUnit dependencies (and the ones you want), you can simply tell intellij to run the tests in the class. I don't think you have to do any special configuration beyond that.
IntelliJ IDEA does not support the auto-generation of main classes from test classes. It will auto generate test classes and methods from a main class. So you could do as @yshavit recommends in his comment and create a main class skeleton and then auto generate the test class via Ctrl+Shift+T. Or as you write your test, keep an interface in sync with it. Then you can auto generate an implementation from the interface.
Otherwise, as I see it, you have three options:
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