Junit ConcurrentTestRunner和@ClassRule

时间:2019-01-08 14:23:33

标签: java junit concurrency dropwizard

我如何通过JUnit(例如具有100个线程)与ResourceRulesRule(dropwizard)和DAOTestRule之类的ClassRules结合执行并行测试?我认为我必须为每个线程创建新的ResourceTestRule,对吗?我将ResourceTestRule实例的创建移至myTest方法,但出现了nullPointerException。...

示例:

@RunWith(ConcurrentTestRunner.class)
public class ConcurrenceTest {    
String TOKEN = "blabla";
@Rule
public DAOTestRule myDatabase =
    DAOTestRule.newBuilder().addEntityClass(MyEntity.class).build();

private static MyManager myManager = new MyManager(myDatabase);

@ClassRule
public static final ResourceTestRule resources = ResourceTestRule.builder()
    .addProvider(RolesAllowedDynamicFeature.class).addProvider(new AuthDynamicFeature(OAUTH_HANDLER))
    .addProvider(new AuthValueFactoryProvider.Binder<>(AccessTokenPrincipal.class))
    .addProvider(new JerseyViolationExceptionMapper()).addProvider(new JsonProcessingExceptionMapper())
    .addResource(new MyResource(MyManager)).build();


@Test
@ThreadCount(100)
public void myTest() {

MyRequest myRequest = new MyRequest(1, "abc");

Response response = resources.target("/things").request().header("Authorization", TOKEN)
        .post(Entity.json(myRequest));
}
}

0 个答案:

没有答案