TL; DR
Yes , you can selectively run tests with jUnit, but how you do this depends on how you start the run.
Different ways to run tests
The simplest way to run unit tests during development is through your IDE . Eclipse, IntelliJ and Netbeans allow you to click on a specific class or method and you will have some options like Run as Test or Test as Java Application and so on.
With Maven , the test driver at test
is Maven Surefire plugin . You can:
Some continuous integration servers can also run tests automatically, but in this case the configuration must be done in the tool and not in the project itself.
Considerations
Unit testing should not be slow. If this is the case, first consider rewriting the slowest ones. Remove unnecessary dependencies using Stubs, Mocks, or Fakes.
On the other hand, generally a slow test usually means that it is not really a unitary but integration test. A common case is tests that make remote calls to third-party systems, or that initialize the entire application on an embedded server.
In such a case, such tests should be placed separately from the rest, either by designing the project or by creating a separate project.
In the case of Maven or Gradle, an interesting strategy is to have a project composed of several modules (subprojects) within which one or more would be projects composed only by integration tests. They are still part of the same code base, so they are easily kept in sync with the project, but at the same time they live away from the main source code and unit tests.