Timeline for How should I test "Glue Functions" without testing that "the code I wrote is the code I wrote"?
Current License: CC BY-SA 4.0
        25 events
    
    | when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 13, 2023 at 2:04 | answer | added | Flater | timeline score: 1 | |
| Jul 5, 2021 at 6:00 | history | tweeted | twitter.com/StackSoftEng/status/1411927824013959170 | ||
| Jul 2, 2021 at 21:55 | comment | added | sleske | Related: Is there a point to unit tests that stub and mock everything public? | |
| Jul 2, 2021 at 16:33 | answer | added | candied_orange | timeline score: 1 | |
| Jul 2, 2021 at 9:15 | answer | added | MT0 | timeline score: 0 | |
| Jul 1, 2021 at 21:14 | history | protected | gnat | ||
| Jul 1, 2021 at 16:50 | answer | added | Dave | timeline score: 0 | |
| Jul 1, 2021 at 14:27 | answer | added | AnoE | timeline score: 3 | |
| Jul 1, 2021 at 9:54 | comment | added | Aaron Butacov | 
        
            
    In the real world, if you trust via testing that func1 and func2 will always return full and proper objects, then for testing your glue, you can relatively safely check a subset of properties that provides evidence that func1/func2 were called properly without checking every single property. That being said, I've always found it's best to have one full integration test to make sure tiny bugs don't slip through. So, one very detailed default test, then just tests to test the logic of your glue function itself.
        
     | 
|
| Jul 1, 2021 at 5:13 | history | became hot network question | |||
| Jul 1, 2021 at 3:50 | comment | added | Filip Milovanović | 
        
            
    A couple more remarks; in your original impl. of glue, when you do something like testFunc1 () => expect func1(2) == 3;, you are explicitely coupling your test to the internal implementation of glue. A tests is supposed to be a stand-in for real client code, and client code is not supposed to know (in this version) that glue calls func1 or func2. The other thing is, glue is kind of doing at least two things - orchestrating the calls, and combining the return values. If combining the return values is not trivial, it can be a separate function. Otherwise a test like == [3, 4] is fine.
        
     | 
|
| Jul 1, 2021 at 3:38 | comment | added | Filip Milovanović | Note also that in functional languages you can produce "hardcorded" functions from parameterized higher-order functions or via partial application, so you can utilize those both for your tests and for the system itself; these basically act as constructors. In OOP you of course have constructors, factories, etc. | |
| Jul 1, 2021 at 3:29 | comment | added | Filip Milovanović | "I don't want to test them by simply mocking what they do" - if you mock what they do then you are not testing them, you're testing the mock. You need to test the actual function, and supply dummy functions for it to call. Then you need to test if those dummies were called, not if "specific [production] functions were called". If your "specific functions" are hardcoded, than your glue function is not testable, which may be OK. If functions to call are an input though, and the behavior to test is all about orchestrating them, then it's fine to do things like "did you call this function?". | |
| Jul 1, 2021 at 3:24 | answer | added | VoiceOfUnreason | timeline score: 12 | |
| Jul 1, 2021 at 0:56 | answer | added | Steve Chamaillard | timeline score: 0 | |
| Jun 30, 2021 at 22:45 | history | edited | Derek C. | CC BY-SA 4.0 | 
        
            
             
                
                    added 1009 characters in body 
                
             
        
     | 
| Jun 30, 2021 at 22:22 | comment | added | Thorbjørn Ravn Andersen | You should verify the behavior. This will allow future maintainers to refactor as you have in place how your glue functions are expected to work. | |
| Jun 30, 2021 at 22:09 | comment | added | Derek C. | @gnat, I'll have to say no. While this is predominately the question I am after, I think there is some differences with mine. I'll happily list them if you want but for the moment I'm going to be lazy. | |
| Jun 30, 2021 at 22:09 | answer | added | Ewan | timeline score: 17 | |
| Jun 30, 2021 at 22:03 | answer | added | Ian Jacobs | timeline score: 0 | |
| Jun 30, 2021 at 21:50 | answer | added | candied_orange | timeline score: 75 | |
| Jun 30, 2021 at 21:48 | review | Close votes | |||
| Jul 5, 2021 at 3:07 | |||||
| Jun 30, 2021 at 21:32 | comment | added | gnat | Does this answer your question? Where is the line between unit testing application logic and distrusting language constructs? | |
| Jun 30, 2021 at 21:18 | review | First posts | |||
| Jul 1, 2021 at 12:01 | |||||
| Jun 30, 2021 at 21:13 | history | asked | Derek C. | CC BY-SA 4.0 |