juan_gandhi: (Default)
[personal profile] juan_gandhi
 So, if you think you call a function in your code, and this function returns current time, or a random number... IT'S NOT A FUNCTION. Your code is function of "random number", or "time".

So, if your code is written as something that retrieves this kind of data, to test your code, you should provide that data. Not just today, but try the time, like 10 years from now. As to "random", You provide the randomness. If your code cannot be fixed to behave as a function of those inputs, make your "random stream" or "time stream" not hard-coded, but substitutable. Mockable. And mock it in your tests. MAKE SURE that you don't provide just happy-path data. Provide anything. A sequence of 100 numbers 4 for random. Time that is 10 years from now. Or even 30 yeas from now.

Make sure that your tests don't depend on anything. Because test Must Be Reproducible.

All these things, I know, are obvious to some, and not obvious to others.

If you still have questions, ask. But don't argue. Because what I say is math. Unless you have another math (some people do), or another logic (there's plenty of them), please don't argue.

I'd be glad to see how all this changes if logic is e.g. linear. 

 

Re: Tests self-diagnostic

Date: 2020-08-27 11:35 pm (UTC)
dennisgorelik: 2020-06-13 in my home office (Default)
From: [personal profile] dennisgorelik
> Но эти ошибки исправляются

Вы так пишете, как будто считаете способность тестов к самодиагностике - проблемой.
Способность тестов к самодиагностике - не проблема, а достоинство.
Проблема заключается в том, что тесты могут далеко не все свои ошибки самодиагностировать.
Например в этом случае:
~~~
static int Return1() {return 2;}
~~~

этот тест:
-----
Assert.AreEqual(2, Return1())
-----
Не в состоянии выявить проблему (passes).

Re: Tests self-diagnostic

Date: 2020-08-28 12:19 am (UTC)
dennisgorelik: 2020-06-13 in my home office (Default)
From: [personal profile] dennisgorelik
Проблема в том, что, с точки зрения бизнес требований, нужно чтобы результат был 1 (это требование отражено в названии метода Return1()).
Но и в имплементации и в тестовом коде - ошибки.

Re: Tests self-diagnostic

Date: 2020-08-28 08:48 am (UTC)
dennisgorelik: 2020-06-13 in my home office (Default)
From: [personal profile] dennisgorelik
> Не отражено.

Отражено.
Я - автор этого метода.
Я знаю, что именно я вложил в имя этого метода, когда назвал его "Return1".


> Первый Возврат, и чо?

"Первый Возврат" - это твоя некорректная интерпретация имени.
Из этого может следовать, что этот метод желательно переименовать (чтобы уменьшить вероятность некорректной интерпретации в будущем).
Но ошибка в тесте от переименования метода не исчезнет, потому что метод, в соответствии с бизнес требованиями - все равно должен возвращать 1.

Re: Tests self-diagnostic

Date: 2020-08-28 07:57 pm (UTC)
From: [personal profile] mikkim08
Возможно, я тогда ошибся. Теперь я понял, что имеется в виду.
К счастью мне такие случаи не встречались на практике, так что я полагаю их вероятность минимальной.

Re: Tests self-diagnostic

Date: 2020-08-29 12:52 am (UTC)
dennisgorelik: 2020-06-13 in my home office (Default)
From: [personal profile] dennisgorelik
Вы имеете ввиду, что вам не встречались тесты, которые successfully pass, а production код, при этом, работает неправильно?

Re: Tests self-diagnostic

Date: 2020-08-29 08:33 pm (UTC)
From: [personal profile] mikkim08
Да, такого типа не встречались.

Re: Tests self-diagnostic

Date: 2020-08-29 09:52 pm (UTC)
dennisgorelik: 2020-06-13 in my home office (Default)
From: [personal profile] dennisgorelik
"Такого типа" - это какого?

Re: Tests self-diagnostic

Date: 2020-08-30 05:12 pm (UTC)
From: [personal profile] mikkim08
Чтобы была ошибка в production коде и компенсирующая её ошибка в тесте.

Re: Tests self-diagnostic

Date: 2020-08-29 08:12 am (UTC)
From: [personal profile] sassa_nf
It's a bug in the specification. It happens sometimes. But the tests only test the correspondence between the test and the code, not between the code and the intention.

Say:
fn is_even(x: u32) -> bool {
   is_odd(x + 1)
}

fn is_odd(x: u32) -> bool {
   x != 0 && is_even(x + 1)
}
the bug in the intention is not very easy to see. (And, by the way, is_odd(2) produces 100% code coverage, which says something about that metric).

Re: Tests self-diagnostic

Date: 2020-08-29 08:35 pm (UTC)
From: [personal profile] mikkim08
It's a bug in the specification.

Разве ? По-моему, это больше похоже на "чётное количество ошибок".

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

May 2025

S M T W T F S
    1 2 3
456 7 8 9 10
11 121314151617
181920 21 222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 23rd, 2025 05:32 am
Powered by Dreamwidth Studios