Junit 4 w/ IntelliJ

Are there any docs / example on making use of JUnit 4 w/ IntelliJ?

Seems like IntelliJ still wants the methods to be named test*. And by default assertions are off, which seems strange (have to turn on by setting each test with the command line option -ea). What is the correct way of running your tests if you write them inline with your class (as supported by JUnit4)?

Thanks for any help/comments...

phil

4 comments

phil swenson wrote:

Are there any docs / example on making use of JUnit 4 w/ IntelliJ?

I don't think so.


Seems like IntelliJ still wants the methods to be named test*.

Hmm, I just annotate methods with @Test and it seems to work OK. (Note
that your method has to be public, your class too.)

And by default assertions are off, which seems strange

You can (and should) change the default VM parameters for JUnit run
configurations: Run/Debug Configurations->JUnit->Spanner button->Add
"-ea" to "VM parameters
http://www.jetbrains.net/jira/browse/IDEA-10055

Apart from those two caveats, it works fine for me.
R

0

Even I am facing the same issue. Problems I faced:

  1. Annotation are not working (Even after providing -ea VM parameters)

  2. I am forced to write methods like testXXXX()

I have no idea what I would be doing wrong. I am using IntelliJ version 7.0

Regards,
\- Janeve George

Edited by: Janeve on Aug 31, 2008 6:11 PM

0

That's strange. Are you sure you are using JDK 1.5+ ?

0

I had the same issue. The problem was my test class was extending TestCase. When the class is a TestCase, IntelliJ looks for Junit3 - method starting with 'test'.

-


// JUnit4
import static junit.framework.TestCase.assertTrue;
import org.junit.Test;

public class SimpleTest
{
@Test
public void booleanSample()
{
assertTrue( true );
}
}

-


// JUnit3
import junit.framework.TestCase;

public class SimpleTest extends TestCase
{
public void testBooleanSample()
{
assertTrue( true );
}
}

0

Please sign in to leave a comment.