Juan-Carlos Gandhi (
juan_gandhi) wrote2020-08-23 09:18 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Entry tags:
TWIMC: tests using random and current time
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
no subject
Вот; и это тоже.
no subject
no subject
no subject
Ну это как-то довольно свирепо уже.
no subject
Сначала мы быстро-быстро написали простенький сервис (ипользуя jetty), а потом писали тесты, для чего нужно было рефакторить код. При этом пришлось выковыривать из бизнес-логики системный таймер и явно передавать его извне. А потом для тестов этот таймер "замочить" (от слова mock).
Ушло на это всё немногим больше часа.
What to test in time-dependent function?
Что именно вы тестировали, что требовало рефакторинг?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
"Should provide that data"?
Re: "Should provide that data"?
Nondeterministic function
Re: Nondeterministic function
Re: Nondeterministic function
Re: Nondeterministic function
Re: Nondeterministic function
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
"Mock" и "mocking" in programming
Re: "Mock" и "mocking" in programming
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
no subject
Remember, remember the 19th of January 2038.
no subject
Exactly.
no subject
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
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
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
время есть область ответственности оси, прикладной софт не должно парить что где там переполнилось вообще
no subject
По первому вопросу - это мы happy path проходим? Его, конечно, тоже надо. Но вообще речь была лишь о воспроизводимости.
no subject
How to test nondeterministic functions
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
Oh, you found some idiots and their opinions. Congratulations.
Re: How to test nondeterministic functions
Re: How to test nondeterministic functions
People that are clueless regarding what is function.
Re: How to test nondeterministic functions
Re: How to test nondeterministic functions
"Idiots" sign
Re: "Idiots" sign
Re: "Idiots" sign
Re: "Idiots" sign
Sings of understanding
Re: Sings of understanding
Re: Sings of understanding
Re: Sings of understanding
The book
Re: The book
Re: The book
Re: The book
Re: The book
Re: How to test nondeterministic functions
Is "nondeterministic function" a useful concept
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
Re: Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Usage of term "deterministic function"
Sweeping the uncomfortable facts under the carpet
Misunderstanding question
Re: "то есть" trick
Expecting answers to unasked questions
Re: Expecting answers to unasked questions
Re: Expecting answers to unasked questions
Re: "то есть" trick
Infallible teacher
Because you are perfect and cannot make mistakes, right?
Re: Infallible teacher
No. Because you need to have a certain level of expertise to argue. Go ahead, demonstrate your expertise.
Re: Infallible teacher
I demonstrated my expertise.
Unfortunately, today you are unwilling to comprehend it.
What kind of demonstration would convince you?
Re: Infallible teacher
Re: Infallible teacher
Re: Infallible teacher
no subject
Мне очевидно, что любое конечное количество моков - это happy path при бесконечном оригинале.
Ну и так же, что все, что придумает конкретный программист, - это тоже happy path, т.к. он уже это придумал, и значит предусмотрел в коде.
Я считаю, что тесты бывают только двух видов: integration - что реально видит наш юзер и regression - настоящий un-happy path из баг репортов. Все остальное - карго культ.