![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
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.
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.
no subject
Date: 2020-08-24 05:07 am (UTC)no subject
Date: 2020-08-24 06:06 am (UTC)Вот; и это тоже.
no subject
Date: 2020-08-24 08:43 am (UTC)no subject
Date: 2020-08-24 05:59 am (UTC)no subject
Date: 2020-08-24 06:06 am (UTC)Ну это как-то довольно свирепо уже.
no subject
Date: 2020-08-24 09:09 am (UTC)Сначала мы быстро-быстро написали простенький сервис (ипользуя jetty), а потом писали тесты, для чего нужно было рефакторить код. При этом пришлось выковыривать из бизнес-логики системный таймер и явно передавать его извне. А потом для тестов этот таймер "замочить" (от слова mock).
Ушло на это всё немногим больше часа.
What to test in time-dependent function?
Date: 2020-08-24 06:01 pm (UTC)Что именно вы тестировали, что требовало рефакторинг?
Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:"Should provide that data"?
From:Re: "Should provide that data"?
From:Nondeterministic function
From:Re: Nondeterministic function
From:Re: Nondeterministic function
From:Re: Nondeterministic function
From:Re: Nondeterministic function
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Re: What to test in time-dependent function?
From:Multiple separate places to modify code
From:Re: Multiple separate places to modify code
From:Re: Multiple separate places to modify code
From:Re: Multiple separate places to modify code
From:Re: Multiple separate places to modify code
From:Re: Multiple separate places to modify code
From:Re: Multiple separate places to modify code
From:Re: Multiple separate places to modify code
From:Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Re: Tests self-diagnostic
From:Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Признаки непонимания
From:Re: Признаки непонимания
From:Re: Признаки непонимания
From:Re: Признаки непонимания
From:Re: Признаки непонимания
From:Re: Признаки непонимания
From:Re: Признаки непонимания
From:Re: Признаки непонимания
From:Re: Признаки непонимания
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:"Mock" и "mocking" in programming
From:Re: "Mock" и "mocking" in programming
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:Re: Is full service test coverage possible with mocks?
From:no subject
Date: 2020-08-24 06:50 am (UTC)Remember, remember the 19th of January 2038.
no subject
Date: 2020-08-24 07:24 am (UTC)Exactly.
no subject
Date: 2020-08-24 08:10 am (UTC)I am not sure I understand what one could do about it. How do you defend against this? Write a piece of code for validating the randoms provided are sufficiently random?
It makes more sense to write tests supposing the entropy is depleted. (and the rng device blocks indefinitely)
no subject
Date: 2020-08-24 01:57 pm (UTC)This one is basically a joke. But if people count on dispersion...
Regarding blocks indefinitely, we would be testing the RNG itself here, right?
no subject
Date: 2020-08-24 04:46 pm (UTC)Re: blocking indefinitely - I was thinking of /dev/random. We can deplete it, and we have seen what happens to the programs that don't think that's possible.
no subject
Date: 2020-08-24 08:28 am (UTC)время есть область ответственности оси, прикладной софт не должно парить что где там переполнилось вообще
no subject
Date: 2020-08-24 01:58 pm (UTC)По первому вопросу - это мы happy path проходим? Его, конечно, тоже надо. Но вообще речь была лишь о воспроизводимости.
no subject
Date: 2020-08-24 02:45 pm (UTC)How to test nondeterministic functions
Date: 2020-08-24 05:52 pm (UTC)What you describe as "FUNCTION", is usually called "deterministic function".
~~~~~~~~~~
https://www.google.com/search?q=deterministic+function
Deterministic functions always return the same result any time they are called with a specific set of input values and given the same state of the database.
~~~~~~~~~~
Why did you chose using non-standard "function" label for "deterministic function" concept?
> So, if your code is written as something that retrieves this kind of data, to test your code, you should provide that data.
Not necessarily.
It depends on what exactly we are testing.
For example, if it is sufficient for us to test that nondeterministic function output contains specific phrase that does not depend on random input -- why should we provide random data to that test?
> Make sure that your tests don't depend on anything.
Test that does not depend on anything - does not test production code.
Do you use non-standard definition of word "anything" or phrase "don't depend"?
Re: How to test nondeterministic functions
Date: 2020-08-24 06:23 pm (UTC)Oh, you found some idiots and their opinions. Congratulations.
Re: How to test nondeterministic functions
Date: 2020-08-24 08:14 pm (UTC)Re: How to test nondeterministic functions
Date: 2020-08-24 09:22 pm (UTC)People that are clueless regarding what is function.
Re: How to test nondeterministic functions
From:Re: How to test nondeterministic functions
From:"Idiots" sign
From:Re: "Idiots" sign
From:Re: "Idiots" sign
From:Re: "Idiots" sign
From:Sings of understanding
From:Re: Sings of understanding
From:Re: Sings of understanding
From:Re: Sings of understanding
From:The book
From:Re: The book
From:Re: The book
From:Re: The book
From:Re: The book
From:Re: How to test nondeterministic functions
Date: 2020-08-25 07:20 am (UTC)Is "nondeterministic function" a useful concept
Date: 2020-08-25 04:01 pm (UTC)Your observation is incorrect.
https://www.google.com/search?q=%22deterministic+function%22
About 451,000 results
https://www.google.com/search?q=%22deterministic+function%22+-sql
About 524,000 results
Google's search count estimates are a bit weird here, but the main point is that there are plenty of "deterministic function" results with the word "SQL" in it.
> Even the second best result - google corrected the term to "deterministic algorithm"
It looks like you forgot to add quotes around "deterministic algorithm" in your search.
Re: Is "nondeterministic function" a useful concept
From:Re: Is "nondeterministic function" a useful concept
From:Re: Is "nondeterministic function" a useful concept
From:Re: Is "nondeterministic function" a useful concept
From:Re: Is "nondeterministic function" a useful concept
From:Re: Is "nondeterministic function" a useful concept
From:Re: Is "nondeterministic function" a useful concept
From:Usage of term "deterministic function"
From:Sweeping the uncomfortable facts under the carpet
From:Misunderstanding question
From:Re: "то есть" trick
From:Expecting answers to unasked questions
From:Re: Expecting answers to unasked questions
From:Re: Expecting answers to unasked questions
From:Re: "то есть" trick
From:Infallible teacher
Date: 2020-08-24 05:57 pm (UTC)Because you are perfect and cannot make mistakes, right?
Re: Infallible teacher
Date: 2020-08-24 06:22 pm (UTC)No. Because you need to have a certain level of expertise to argue. Go ahead, demonstrate your expertise.
Re: Infallible teacher
Date: 2020-08-24 08:12 pm (UTC)I demonstrated my expertise.
Unfortunately, today you are unwilling to comprehend it.
What kind of demonstration would convince you?
Re: Infallible teacher
From:Re: Infallible teacher
From:Re: Infallible teacher
From:no subject
Date: 2020-08-28 09:27 am (UTC)Мне очевидно, что любое конечное количество моков - это happy path при бесконечном оригинале.
Ну и так же, что все, что придумает конкретный программист, - это тоже happy path, т.к. он уже это придумал, и значит предусмотрел в коде.
Я считаю, что тесты бывают только двух видов: integration - что реально видит наш юзер и regression - настоящий un-happy path из баг репортов. Все остальное - карго культ.