Assuming my understanding of the question is correct, it actually can be done using JUnit. The code below was used with JUnit 4.11 and allowed us to split all tests into 2 categories: "uncategorized" and Integration.
IntegrationTestSuite.java
/**
* A custom JUnit runner that executes all tests from the classpath that
* match the <code>ca.vtesc.portfolio.*Test</code> pattern
* and marked with <code>@Category(IntegrationTestCategory.class)</code>
* annotation.
*/
@RunWith(Categories.class)
@IncludeCategory(IntegrationTestCategory.class)
@Suite.SuiteClasses( { IntegrationTests.class })
public class IntegrationTestSuite {
}
@RunWith(ClasspathSuite.class)
@ClasspathSuite.ClassnameFilters({ "ca.vtesc.portfolio.*Test" })
class IntegrationTests {
}
UnitTestSuite.java
/**
* A custom JUnit runner that executes all tests from the classpath that match
* <code>ca.vtesc.portfolio.*Test</code> pattern.
* <p>
* Classes and methods that are annotated with the
* <code>@Category(IntegrationTestCategory.class)</code> category are
* <strong>excluded</strong>.
*/
@RunWith(Categories.class)
@ExcludeCategory(IntegrationTestCategory.class)
@Suite.SuiteClasses( { UnitTests.class })
public class UnitTestSuite {
}
@RunWith(ClasspathSuite.class)
@ClasspathSuite.ClassnameFilters({ "ca.vtesc.portfolio.*Test" })
class UnitTests {
}
IntegrationTestCategory.java
/**
* A marker interface for running integration tests.
*/
public interface IntegrationTestCategory {
}
The first sample test below is not annotated with any category so all its test methods will be included when running the UnitTestSuite and excluded when running IntegrationTestSuite.
public class OptionsServiceImplTest {
@Test
public void testOptionAssignment() {
// actual test code
}
}
Next sample is marked as Integration test on the class level which means both its test methods will be excluded when running the UnitTestSuite and included into IntegrationTestSuite:
@Category(IntegrationTestCategory.class)
public class PortfolioServiceImplTest {
@Test
public void testTransfer() {
// actual test code
}
@Test
public void testQuote() {
}
}
And the third sample demos a test class with one method not annotated and the other marked with the Integration category.
public class MarginServiceImplTest {
@Test
public void testPayment() {
}
@Test
@Category(IntegrationTestCategory.class)
public void testCall() {
}
}