Closed AbdullinAM closed 4 years ago
Fixed in kfirst-tests
Does this really fix this? In general, model solution could be throwing more specific exceptions, too
From what I've seen in random tests, in model impls we always throw the exact exception required in the task description.
We could add a parameter specifying the expected exception, but IMHO it would be an unnecessary complication at the moment.
JUnit fuction
assertThrows
check the type of catched exception usingisInstance
method. In some cases it results in different behaviour of kotoed and local tests on the same input. Example from student solution of tasklesson6.plusMinus
:If you run this solution on input string
"~JD*_c\\teH:QnPQudT,8z"
it will throwNumberFormatException
. The requirement for this task is to throwIllegalArgumentException
when input string has incorrect format.If you will run local test using
assertThrows
, test will successfully pass, becauseNumberFormatException
inheritsIllegalArgumentException
, thereforeIllegalArgumentException::class.java.isInstance(NumberFormatException())
returnstrue
.If you will run the same solution in kotoed and random tests will generate similar input, the test will fail, because kotoed checks the exceptions like this:
This is really confusing to students, because they don't understand why the same solution works locally and fails on kotoed on the similar tests.
I think we need to add some custom
assertThrows
method to local tests that will behave like the checker in kotoed.