IntelliJ: run one method like BlueJ

So, I'm currently using IntelliJ (2017-3, if that matters), but in my current project I need to test individual methods with specific inputs (mostly text-Manipualtion) so I remembered BlueJ from school, where you can create objects and run single methods without writing additional code. So, I wonder if there is a plugin or other workaround that gives me this function in IntelliJ?

(Using BlueJ parrallel splits the project into IntelliJ, so this is not an option)

+4
source share
2 answers

To run the class method, I would recommend setting up unit test (see Testing and code analysis). This is a bit more configuration work than BlueJ's on-the-fly method, but it's worth it because you can easily repeat the same tests and even automate testing. For instance.)

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 another statement, “No, x Not equal to 1!”.

+2
source

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

To convert an existing project to a maven project, right-click the project module, click Add Framework Support, and check the maven field.

pom.xml. , JUnit:

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

, , "@Test". .

0

Source: https://habr.com/ru/post/1690212/


All Articles