6

So I currently use IntelliJ (2017-3 if that matters), but on my current project I need to test single Methods with specific inputs (mostly text-Manipualtion), so I remembered BlueJ back from School, where you can create Objects and run single methods without writing any extra code. So, I wonder, is there a plugin or other workaround that gives me that feature in IntelliJ?

(Using BlueJ parrallel breaks the project for IntelliJ, so thats not an option sadly)

Hobbamok
  • 502
  • 6
  • 17

2 Answers2

2

To run a method of a class, I'd recommend setting up a unit test (see Testing and Code Analysis). It's a little bit more work to set up than BlueJ's facility for running methods on the fly, but it's worth it because you can easily run the same tests repeatedly and even automate testing. E.g.)

if (x=1){

    DoSomething();
    System.out.println("yes, x = 1 !");
}
else{

    SendError();
    System.out.println("No, x Not Equals 1 !");
 }

If Really x = 1 , you will see the output of the program "yes, x = 1 !". If not you will see the another statement "No, x Not Equals 1 !".

lucidbrot
  • 3,789
  • 2
  • 27
  • 54
1

You can set it up as a maven project and use JUnit to run each method as a test.

To convert your already existing project to a maven project, right-click the project module, click "Add framework support", and check the maven box.

This should generate a pom.xml. Add a section containing the JUnit dependency:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Then create a class containing your methods in the test source folder and add the "@Test" annotation to each. You should be able to run each method individually after that.

Lorn
  • 64
  • 1
  • 3