Assertions for non-deterministic behavior | بلاگ

Assertions for non-deterministic behavior

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

Vote count: 0

Does AssertJ (or JUnit) have a way to chain, in a single (fluent) expression, several assertions on the same unit under test where one of the assertions may throw an exception. Essentially, I'm trying to assert that:

If unit under test X doesn't result in a particular exception, which it may, then assert that a particular property on the unit under test doesn't hold. Otherwise assert the exception is of a certain type.

For example, is there a way to express the assertion that the following erroneous code could EITHER result in an Exception or in a situation where strings.size() != 10000:

@Test/*(expected=ArrayIndexOutOfBoundsException.class)*/
public void raceConditions() throws Exception {


    List strings = new ArrayList<>(); //not thread-safe

    Stream.iterate("+", s -> s+"+")
    .parallel()
    .limit(10000)
    //.peek(e -> System.out.println(e+" is processed by "+ Thread.currentThread().getName()))
    .forEach(e -> strings.add(e));

    System.out.println("# of elems: "+strings.size());
} 

AssertJ has a concept of soft assertions, are those to be used in the scenarios like that? I'd appreciate some code samples if so.

Or perhaps there are better frameworks specifically design for this type of scenarios?

Thanks.

asked 36 secs ago
Simeon Leyzerzon

...
نویسنده : استخدام کار بازدید : 8 تاريخ : چهارشنبه 25 بهمن 1396 ساعت: 1:25