Suponiendo que mi comprensión de la pregunta es correcta, en realidad se puede hacer utilizando JUnit. El código siguiente se usó con JUnit 4.11 y nos permitió dividir todas las pruebas en 2 categorías: "sin categoría" e Integración.
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 {
}
La primera prueba de muestra a continuación no está anotada con ninguna categoría, por lo que todos sus métodos de prueba se incluirán al ejecutar UnitTestSuite y se excluirán al ejecutar IntegrationTestSuite.
public class OptionsServiceImplTest {
@Test
public void testOptionAssignment() {
// actual test code
}
}
muestra A continuación se marca como prueba de integración en el nivel de clase que significa tanto serán excluidos sus métodos de prueba cuando se ejecuta el UnitTestSuite e incluido en IntegrationTestSuite:
@Category(IntegrationTestCategory.class)
public class PortfolioServiceImplTest {
@Test
public void testTransfer() {
// actual test code
}
@Test
public void testQuote() {
}
}
Y la tercera muestra demos una prueba clase con un método no anotado y el otro marcado con la categoría Integración.
public class MarginServiceImplTest {
@Test
public void testPayment() {
}
@Test
@Category(IntegrationTestCategory.class)
public void testCall() {
}
}
¿Puede explicar el por qué? -1'd esto? Usar TestNG es una buena sugerencia. –
De acuerdo. TestNG es lo suficientemente maduro como para ser una caída justa en reemplazo. – serg10
Tx Tom por votar nuevamente, también me gustaría saber el razonamiento detrás del voto a favor. –