CppCast - Unit Testing

Rob and Jason are joined by Oleg Rabaev. They first discuss some papers from the latest ISO mailing and a new feature in Microsoft's vcperf tool. Then they talk to Oleg Rabaev about Unit Testing methodologies and why it's important to write testable code.

  • Play Speed:
Content Keywords: data
00:00:02
episode 263 sleepycast with Gaston lagrave corded September 2nd 2020

00:00:08
this episode of cpv Casa sponsored by Klein power tools the open-source Visual Studio extension on a mission to bring clang llvm magic to see post developers on Windows increase your productivity in automatically modernizr code. Now get had a bug's Daisy elvehjem static analyzers and CP core guidelines checks in the comfort of your ID start today at Klein power tools.com.

00:00:45
And it sucks that we discuss ISO papers and a new-build Time analysis tool for Microsoft.

00:00:52
Then we talked to Oliver, babe.

00:00:55
Old trucks, what's that unit testing and the importance of making your code testable?

00:01:21
Welcome to the store 263 of CBP Cass the first podcast for super supposed to help his bicycle supposed to bell peppers grow strawberry from Joanne by my co-host Jason Turner Jason. How you doing today? Are you done doing good? I want us more about this announcement. I saw on Twitter right after recording last week. That's something you want to talk more about. I mean my announcement that I'm working on a book was preempted butts was no it's it's out there for pre-release at the moment. I'm still working on it by now out to let's let's talk about it more after I actually officially finish the book by the listeners are curious can go and fight that that's out there. How far along is it so far?

00:02:08
So I would say probably about 85 90% done with a book on people's house best practices and it's supposed to be just like simple actionable items is my go about each section has intentionally very short and and simple you hadn't planned on officially announcing yet, but it kind of got out there a little bit last week while I hit the hit the make this book available and then because I had talked about it on Twitter that I was going to do it and then I said let people register to be notified when I was available for resale and then I made it available for b-cell and then people start talking about that on Twitter, but I was still just going to try to keep it quiet for a little bit longer until the book was done. I apologize then that's fine. I'll talk more about it when it's when it's finished then okay. Alright. Well, I'll just have like three two piece of feedback. This was from a few weeks ago when we

00:03:08
Add a Slowdown on talking about his book modern simple sauce for absolute beginners and this, darn right? It says stop calling modern than modern from the decade now and get that people for what is a slow-moving Glacier, but they qualify erazno useful information and just makes more makes results more difficult to search for in the future idioms change in Posey. 26. I really don't want to continue searching for Martin simos was only to find Pre-Sequel Stefani material the modern C. Plus plus that term came about way before 6:11 and Dad but the term the way we all use it right now, I think was because of Scott Myers as modern C plus plus book right act of modern C plus plus which was 2012. I was actually released. I think I should have checked.

00:04:03
Yeah, I'm not really sure you're ever able to get people to stop using that term. I don't know. What do you think is no, I don't know because it's a you can there's there's a problem because you can be using C plus plus 20 but still be using C plus plus 98 techniques when there's better idioms in better options available. So how do you qualify that you're using the latest and greatest past practices and and idioms that are available. I was just I was just running through some of these things in my book Concepts and how much they can make the code better but most people don't have access to Concepts yet. So I don't know. How do we how do we call that when it's when it's time to say yes modern C. Plus now includes Concepts. I don't know what we'd love to hear your thoughts about the show. You can always reach out to us on Facebook.

00:05:03
Twitter or emails at feedback at cvs.com and don't forget to leave us a review on iTunes or subscribe on YouTube joining us. Today is Oliver Bath House developer who cares deeply about proper software design clean code and testing experience in building large Financial large-scale Financial trading and risk management systems in memory databases in Reidsville. Library's only welcome to the shop. Thank you. How you doing? Nice good. I think we have to congratulate you on possibly the shortest bio that Rob has ever had to read it. All right, then. I appreciate the the to the point. Let's hear about the things that you really care about is a developer. I like things simple and short that this was not always the case, but you know, I see you evolve to be a simple wish it is good as the older you get the more you ask the question of how little code. Can I write to solve this problem?

00:06:03
Will all agree. We got a couple news articles to discuss. I feel free to Counting these and I'll start talking more about what you're up to. Okay? Okay. So this first one is the 20 2008 ISO mailing is now available. Is it for the short one piece of brings out every month? So there's only so much that it makes it per month any highlights for you here Jason, not particularly, but more questions then then highlights from my perspective at these monkeys mailings are coming out regularly, right and the Committees are still meeting remotely think I've heard of a single paper that was accepted for C plus plus 23 yet. Have they been accepted? Is there some of these things how do we deal with the fact that they're not having the meetings were people vote on things and it officially moves forward. I think I'm wrong, but that's all we talked to someone who said that they're basically no voting on these things.

00:07:03
Virtually, no kind of giving a tentative thumbs up thumbs down with the plan being that you know, these things that we are virtually approving now we want to actually vote in person on when were able to okay that sound right but no but I like the fact that they have was a full stack Trace in the transactional nominee. That's looks very interesting to me personally. Okay. So based on your actual memory would be interesting to you one of these things like it was the hot new topic in like the early 90s and then people stopped caring about it and there's been proposals in and out of the C plus plus standard what what are your thoughts on transactional memory? I means the simplify the multifarious

00:08:03
What is extremely difficult right especially these days with modern processors that are some V optimized seems like like like free and write a very difficult to write and I think transactional memory what's facilitating that so basically the way I look at it is that you make a change to a bunch of mammoths and then someone else's will only see the changes when you to commit a transaction. I'll how synthetic when semantically it's going to look like in court. I haven't actually look at the paper right but this is something is very interesting oil changes at treated as atomic right? So just like Atomic variables in C plus plus 11 and all so this is something video just I would definitely leave like to play with it is something stable lights Dental. Do you know, can you can we think of this like database transactions like begin transaction do some stuff and then come nuts?

00:09:03
Come calling me to start studying right I'm caught a red black wavy LG or I'm going to attach table. It would be very helpful there. I think there are some hash tables for example of implementing using what's the location of the night and it was a very extremely difficult to toboggan design black magic magic. I'm still a slight quite literally, so I think it would really be helpful. That sounds stack chase, you know, if I think Java if they always had that they would be nice to have something like that in the first place that's on the cord down but to actually be able to make that proposals based on the Boost back-trace.

00:10:03
I swear I probably exaggerating hear that it's is going to face problems because you know, like the standard doesn't acknowledge that there actually is a stack or something like that. Right? Like cuz this is kind of thing that it's already on its it is in lwg. So I made it past lwg Evolutions that we were going to say. Okay. Next thing we have is an article from the visual C plus plus blog and this is introducing vcp / time. Trace principles was Bill time analysis, and we had Kevin Trudeau and Scion a while ago talking about this feature. And this is actually a guest post from a game developer from Mercury steam entertainment.

00:11:03
Familiar with that game development company, but he no use the people who build inside. That's okay that we talked about with Kevin and actually wind up submitting a new feature to it. And it's too I put this graphic actually View and chrome which is pretty cool. Yeah, that's exactly how clings time Trace all sorts and I thought was interesting how they found some issues in their own code using this one of the things they mention is a particular default Constructor, which is defined by the compiler that was taking 3% of their total bill time. So I just went and put in that instructor themselves and save 3% on their bill amazing.

00:11:53
At least it's only available for visual studio right for visual good old days.

00:12:02
What clean clean does have similar functionality as well? I figured it's parameters called now, so I should analyze perhaps that yeah something else for our listeners to look into if they're interested. Okay, and then Jason do you want to share this last one? This is a post on the CPP subreddit about destructors. Like how come GCC incline or giving you know, one of them's allowing us to come by on the other one is not and it was using a technique that I recently had on C plus plus weekly for having multiple destructors in your class with C plus plus 20 is Concepts because you can constrain your destructors. So the destructor only exists if it matches the constraints and this person wanted it to be virtual or not virtual and I just thought it was fun. This is like, you know, just because it's so easy to ask these questions today if you managed to formulate your question, no way the

00:13:02
People can like read and provide a God willing to and whatever and the top answer on Reddit is a quote from the stranded a virtual function shall not have a trailing requires Claus like it's just right there, but they got like the perfect answer just by asking the right question as well formed in it was timely with C plus plus 20 psi. I like the article. I'm not even an article. It's like a 3-minute read.

00:13:27
Okay. So Oleg see you actually reached out to us. Asthma coming on the show after we recently talked about one of those. Jeff brains likes Taylor Community posts in are they talked about and what unit tests are supposed to help her using unit has libraries and over a third of respondents that polsat. They don't write unit tests for C plus plus was so what are your thoughts on that guy? After I think it's if George Costanza with a C plus plus programming you would say the worlds are colliding at this point.

00:14:11
I mean I was completely shocked. Yeah, I need this is 2020. I can understand 10 10 years ago, right? I think the unit testing at self picked up at the beginning of a gentleman with my fists unit test probably in 2008 without even realizing that I'm riding unit test because I just wanted to write a small program that sort of test a small piece of court and I had like main function where I would have liked a sweep statements, did our house but I had no idea it was the unit. That's what I actually was eat that and then I was introduced to the Google test framework, right and for me person with a paradigm shift and in the van like it since about 2010 I have been cooked.

00:15:00
So I unit test in general improve the quality of your cord. I think someone mention if you write a queen called you don't have to write unit tests ran in one of the comments you mentioned on the show. So so I was working on a project but it's actually in the end of the day today. So I thought I'll just grab it and do genetic terms. Basically, it's moved. It has a sequel compiled and basic datathon composite in this is us has alter table decorations and running database replication of the class that should never hold on down. It should be like 24/7 traditional stuff like that process is dance a thousand messages a second has a lot of Lock 3 Bait of structures, so he's extremely

00:16:00
What system night so we hired a developer into the gym who was supposed to help out sort of support at an extended personality and in case in case you know something. Just just something happens to me personally fit right into cold like jabez's decides to give him a retirement plan. So he joins the team and I expect the questions, right? Like it's naturally very friendly. She doesn't ask me a question on day one. He doesn't ask any questions me to TD the week goes by two weeks ago. I am starting to think the guy doesn't like me then why don't you ask me a single question. It's getting complex system says, I don't need to every time I

00:17:00
Find out how Pacheco component warts I just woke up too fast. And it's their system had several thousand units. So that's sort of This Is My Philosophy personally and I tried what you know Pritchett Eye, you know, I was not always like that. I wrote a lot of spaghetti squash at the beginning of my career just like everyone else. Let's be honest ice you might sometimes do the same thing right then it's not up to me to judge by always tries to improve my design skills. And I feel that it has to be some kind of methodology that allows you to achieve that is it was for example, we all agree. It's much easier to program in Peoples Plaza in December, right? I'm not sure about suppose + 26. If you have an integer and

00:18:00
Trying to sign string a string to an integer variable. The compiler will not let you do it right. You can just move them from doing that things like that. So it's built into the language where the compiler sort of is guiding you in not allowing you to do certain things which would be which would be stilted right now with that sting II tree testing as my guy to a design whenever I work on any piece of quartz. I always think how am I going to test it? And I don't always think about particula library or service. I always look at the system is a hawk. How am I going to test it? Still three simple rules that I try to follow Mom cried all the small functions knife that a lot of fancy jogging out there. What if you wanted to say promote some sort of like a developer solasofia you want to make it as simple as possible night.

00:19:00
Just like to buy it. So guys, we should all the tides motor functions the coach of the modular anything recently had several months ago was it yes school. It was actually pretty funny and you mention about small function of this is just basic stuff, right? The next thing would be no Cycles. So when he joined Bloomberg, are you all know that I'm sure this is good news to know that John Lakers, right? And he has a lot of YouTube videos ride and I watched his stuff, you know, and some of these ideas of evolution Evolution it right? So what one thing that I take away from myself and is the car article design and no Cycles under any circumstances with some exceptions of elaborate and what does it mean like if you have component components, they should not be cyclical dependencies.

00:20:00
If you have anything, I like component see depends on component B component age should never depend on components it right because be depends on a you should not have sickle defenses and functions and Colossus in libraries in Services. You should not be in my opinion. They should monthly cycle and I had core recycles like and once I started falling philosophy and actually improve the design and test ability of the court. So actually John mentioned that one of the day ask him. I've seen one of the dogs I could be on the show me and it's from some of the YouTube videos. What do you think the biggest benefit of modules so I think John sat July cassette for me, it's almost impossible to create a cycle cycle depend on with module. Yeah, that might have been his interview. I'm here.

00:21:00
When you say some more functions than everything to come small we have smoked glasses smaller Library smallest Services. You just break your components into smaller pieces and make them usable. No cycles and number c test rules that actors in The Following make a quart testable and design for testing night. So if you do that and even if you don't need any other books with 1000 definitions, right, which a person can get very discouraged from budget. What is this kind of brutal deaths driving behavior driven development. Where do I start to be productive? So I think you should always start with a simple princess and it is like eight 80 20 Rolls by Falling is principles. You will cover 80% of your design in my humble opinion. So I

00:22:00
So do I just give an example of thefts become your documentation? They expressed you express your core through the test and see if I can file explorer or they went box tonight. That is why I like one. But it is only the Min function that I said. I'm doing the sea out and we'll keep being that would rather use that sort Marcus or acquire Marcus Wright that that's This Is My Philosophy. This is like if I started on something you want to test something like I don't mean function I will have it that fixture and that's where I will basically play with my court stuff like that drive using that sort Marcus or expect or require depending on their framework you use instead of doing the Cialis and you mentioned like a ton of terms just now so it kind of sounds like you do what most people would call Tess.

00:23:00
Urban Development, is that fair? Or that would be right. It's it's it's again. It's it's it's one of those arguments that a couple of camps. It's like what's better the IRA max, right? Right and some people do it this way some but I don't personally because he knows my design. I mean, it's just more difficult for me like that because then you start losing I don't want to criticize. So I don't want to like the basic light on but I will write a test for Every public function of my cloud talk about public functions, right? That's the only thing you can really fast. I will write a task at least one test for Every public function function in you know, who killed a contract of the function right and then test

00:24:00
The exceptions and the corner case and stuff like that. I don't test undefined Behavior.

00:24:10
Sil so you're a. Sounds like, you know, when you see the people to do things like pound to find private-public to be able to make their own on know it's a No-No for me if you do stuff like that and maybe your closet and you should break it up into smaller, that if you have too many private functions that are in itself provide some testable functionality. Maybe you should make them part of the another component and use that component of composition inside the class right of the client right now, but I would never do this. I don't like to pull up my courts with things like that for the sake of our listeners that is possible technically with most compilers that you can do that and then all of the private functions in a class become public and yeah, it said that it's not good.

00:25:10
I tried it was like a while back but no you don't want to get too caught up in terminology. But so but I do kind of wanted to dig in a little bit. Sound like what you you you do Advocate specifically for what most people call unit, testing individual functional testing elaborate on a different type of test that after seeing what I think I think the everything is a unit of integration that everything else is just a little bit too far with right if you think about it and I'll explain what the unit that stays in my humble opinion and integration tests. And I think maybe it's a concept that I heard and one of the

00:25:56
Fletcher I believe you done somewhere on YouTube and I liked it Concepts all talk about its interaction test. What is the unit that I never heard that before? So now is the chance? What is the unit? That's right. So do you need to ask is basically it's just a small program with minimal set. Of course. I have a small problem with exercising from that apart of Republic function know what does that mean as you build your component testing vector or Instinct was right, you will only because Vector in itself is more like a vocabulary. It's just it doesn't interact with any other components Pie as you build your class Karachi, right? The testing becomes a little bit more complex, correct? Because you have to do more things just to set up.

00:26:56
Court in order to test your high-level components, so those kind of testicle interaction test and then write the equation test integration test is either unit test interaction test with external dependency meaning if you are leaflets of your ID to be successful and you have nothing but I'm 18. Now, you know, you have an external dependencies on a database right? Let's say it's a SQL Server database. So in order to test your court, you have to have an instance of the database running so you have the dependency and that's makes it a little bit harder to test duration fasting is more harder because what if it's me a composite of Dennis like you use some kind of message queue mechanism that requires the starter or are you talk to your service over TCP connections night that's integration to her.

00:27:56
The community tends to Mildred interaction test integration into one concept. I split it just so to make introductions are just like interaction integration tests, but without a dependencies and marullus. I always try to achieve unit introduction test and remove external dependencies and their ways of doing that but you have to design your system. Wait to do that and I can elaborate in that for example in the in the story that I told you the beginning about this large-scale, you know database one of the things I was able to fast without any kind of dependency is communication protocol application is Juan Lugo stop. In other one goes down. You don't think starting in exchanging information and everything continues working. How do I do that without having any kind of some of the penalties on file on TV?

00:28:56
Bo anything like that, so it's a job. I think I like dependency injection site. So what you have let's see you have a component a that talks to component D using components C and components C is TCP IP interface, right? What's a wearing pink service pink line? So the pink line cord just says, you know, I'm sending something using the to see right ski is the server is the client D is the Middle where so how do you test that? Okay. Are you have to start your silver right that will listen & Vine in the socket and then declines will open to do you do it like that? You know, what you do is since you are communicating between the client and a server using thing Bill wear.

00:29:56
Little bear as an abstract interface, which has a function sin examples and interface can be plugged into the file injected into themselves injected into the climb court and provide in Mammoth implementation instead of sending data over physical Network. Send it to her over, you know, just dumping into the vector of bites right and do the same thing for the service I so do you think you're set up what you basically place than interphase the actual Network wear with you on implementation bright, which is the name of the implementation and you can test your system and twins without external dependencies my scale of SQL Server database right unless you start of the service, right?

00:30:56
Is something that you can bring up in the process, right? You don't need the actual service instance running, right? So what is the SQL Server developer some icicle develop a sort of had a little bit and thoughts like how we going to make our system is much easier to test that would provide ability to start some kind of Life database engine on the client with any kind of external dependencies that was completely in Mammoth it right with a simple interface and you can test your call this way. I looked into one of the graph databases such thing as new food GA and actually did that they say, okay guys, if you want the unit that you don't have to run the database engine that is an amendment limitation. So when I ride my bike or whenever I haven't you don't always have this chance because sometimes you depend on other systems or on the open source project was simply don't but if you're working on infrastructure component, you should always designer.

00:31:56
Four clients so they can test it easily without external dependencies. It will make it you will start thinking differently right now. So, you know what I have separate so that I could run my stuff in a y de morte or is actually it's too much better design. So this is you don't want to turn you into gratian test into unit that that's the goal. It's not always possible, but that's what you want to do.

00:32:27
Winner of the discussion for just a moment to bring you word from our sponsors. Klein power tools is the open-source Visual Studio extension on a mission to bring lvm tools. Like Klein plus plus clang-tidy incline format to C plus plus developers on Windows increase the productivity and modernize our simplest code with automatico Transformations PowerBack client ID find settling bugs blazing lvm static analyzer in CP core guidelines checks. Don't put off Main light switches or learn. How does a compiler flags flying power tools come to the powerful user interface to help you manage the complexity directly from the comfort of your ID never miss potential issue by integrating claim power tools into your work was picking fig herbal Powershell script for CI CD automation start experimenting on your coat today. Check it out at Klein power tools.com.

00:33:12
So you talked about these three types of testing that you focus on do you sign kind of weight or importance differently on him? Like how many units as you have compared to the number of integration interaction testing the usual applicable to lower-level components Ryan and you do want to ask them in and out like you you want to do it to extreme you want to have complete, it's not as you go higher level. It becomes almost impossible because they might have interactions right amount of ways you can you have so many components in the pipeline write the amount of dependents becomes extremely difficult. Right? So you will number of tests will go down but you do want to have to ask that will sort of Goodwill sanitize your cord sort of speak right? I mean in this case like approval texting glad you can generate a bunch of with a files the input files, which becomes a

00:34:12
Golden car to ride and then whenever you change the change the Accord right? Make sure that isn't that I know bars. You can run through the same aggression, right and it will it will hopefully nothing is broken. Everything will get past right? But if it comes very difficult to test as you go higher level, so more tests on the union side, they will need to do a stats on interaction degrees inside, but they have to be so I think 80/20 rule Works yet. So they will be 80% off that's will be on the union side and 20% think I should sign. Okay, so I'm thinking about a couple of things are like I've done some people that say that they don't really do unit test. They only do Behavior test because they want to be able to swap out the implementation as long as it's still get the same behavior from the system. Now, I was not thinking about that when I was working on my strutting engine chai script years ago, which just for the record I would maintain it all.

00:35:12
Time now but coincidentally we have almost no test in there that test the actual cplusplus like test like I parsed this and I expect this AST back instead. We just wrote things that only test the scripting engine. Like if I put 5 in do I get an integer 5 back out? If I do 5 + 4 do I get 9 back out of the system which gave us very good code coverage ultimately and let us know if any of the Behavior broke in the system, but I'm curious about your opinion. Like would you say that I did a bad job testing the system. I think you did One Direction theft unit that you do want to test every component and I think the behavior of the human testing you linkable to unit test interaction test. It just sort of like synthetic sugar right depending on the framework for use with like if when giving sort and right input when you know, you do like I can't catch has the soup.

00:36:12
What's the time sheet as to not what I think what you did you did more interaction test and I see it all over the place. You did a good job because you do have coverage but I don't think you have enough unit. That's because you don't want to test your boxer. You do want to test The Alexan right? You do want to test every low-level component, right? For example. If you are interested in class, are you going to text Justine class from your client called by using it or you going to write unit tests for the steam course? You should probably write any of this for the tank last night. That's a good point. Yeah. Yeah. Yeah. So I think you have more introduction test. I don't think you have any external dependencies that right because it's description language you but yeah, I know it's ya so but possibly you don't have enough unit. That's yeah and I think the most important that the DNA test because once you test your metal components if you have a good coverage you just like a new line on them working you never text

00:37:12
Low-level components in terms of high-level components. You just did a line on them working. That's it. And obviously you need to test and plant that's like you're providing input to something else, right? Yeah dolezal say placeable. Sometimes people will go wild with unit test and they will shine the integration tests. That is another thing like that everything right? Like I think Mark is used to focus on expands to break the dependency right now, if you don't control the infrastructure, what's a and you talkin to a particular service by giving some Jason input you get some Jason output, right? So you don't want to start out that service in the whole infrastructure. So you mark it out you usually what you do you have a class after interface with some methods, you know that gets you don't think we're some data and John's you some kind of response. So you Market in the real implementation, it will go into that sort of us and we'll let me

00:38:12
It's going down tried finding a limitation. If you just going to be 64 never you called yet someday that you will get your own hardcored it or whatever all that means you do that so that you break the dependent and you can turn you on so if you could unit test your components that interact with other components over over over the stern, but some people take it to this team that will make that will make everything right and I don't think it's useful because it could do that. But you will have to ride to Mendes amount of what I think would be unnecessary. That's because at the end of the day you do want to do integration testing night and integration tests usually will catch a lot of errors that one missed you in the market because then that you want to test the whole system going back to my database example, I had only

00:39:12
I did not really have much. I mean I did have my walking dead, but it was very limited the way I achieve that you can also Save Mart in his I replaced all the communication with apps that again so that I can test everything in memory. Right but I would not Mark every component interaction between any other component know I would just use the other components as they does Dave know. If you have a string in exact time, you build some would say in and out like some other class which includes this thing in the vector. You don't mind that place and it isn't reckless like no you just use those classes like you did with your scoop thing that right at the end of the day. You don't mock. You have your plot of sending you have your Alexa try if you have something else going there and you have a client in to fix you provide an input you get it out. I'm a fan of that. You should really fast each component. That's fine. But at least you have proper interact.

00:40:12
That's right. So an intact, you know, once I give the presentation and you know, I decided to make a little controversial friend. I was trying to prove the point at 2 to have when you have external dependency in a way to control things. It's much better to instead of marking just provide the synonym of implementation and a lot of times just that the system is a hole. So my second flight would say like mocking is evil right? Just just wake up people right now. You should know when to my mom not to mark but sometimes you have to do it as special marking is good. When you do that Sarah conditions, for example, if you are testing the database, even if you have your in Mammoth implementation, right, how do you generate connection address? Right? How how do you drain your day that something had bad happen? It's difficult because

00:41:12
On your mark, that's a different case for marking. I really like that point. That mocking is particularly useful for the error case. I find that very interesting on the way to consistently guarantee. You're going to get an error. I wouldn't be against Mike and every component in the system that would just be insanity and I have seen asking you to do that by Falling this practice is right. Just write modular Court don't create psychos fantastic what it will it will not let you make that decision decision. It's like you become your own compiler so to speak right if you just discipline enough that you follow this video is like riding small function is very easy principal to follow and it's

00:42:12
The books, you know that is a single responsibility Principle as you have to have the smallest amount of but I like you when you try to explain something to someone you want to make it simple the most simple you make the easiest will be accepted. So I think running full function does babies it comes to creating no Cycles is also use it, So now I have great like I have my other three sort of statements which I want to run by you which also guide my sofa design. He's a component. It's not properly designed. OK number one is a component is easy to test it is a good indication. That is probably doesn't mean you can still have mass inside the court in Plymouth this but it's a good indication that the problem now is the component is properly designed it's easier to test. So whenever I ride a class this is why I'm asking myself these three questions in general. Is it easy?

00:43:12
If it's easy to test it's a good indication that is part of the design and that's what design for testing means for me.

00:43:21
Now I appreciate those those Skyline sound good. But how do you get the towns like a lot of weight in my ear like while you know unit test a lot but not too much mock some but not all the things. Like how do we start to develop this this mindset this intuition for what is good testable code? What is good testable? I mean we have to practice I found me. It was like I find a difficult sometimes to bring it over right at the Finish Line your boss wants like once you get it. You cannot do things out of a shelf unit has a lot. There is no answer unit test that you can ride now interaction integration test reasonable amount, but you are limited because they literally you could have

00:44:20
Total explosion that right because there's so many ways. You can use a component only when you need to test for errors conditions or is it is accomplished dependency not external dependencies, but even like with with in your project, sometimes you would do Mocking just two separate in my other part of the system so you can test it easy, right but I wouldn't like everything absolutely and integration tests try to turn them into unit test and Direction test by remove external dependencies. And the way to do it is use dependency injection communication protocols or protocols that talk to file systems on Massachusetts databases. When did mammoths implement it is sort of like mocking except that the actual court is executed. It's just whatever would be executed in the shoulder beside is actually executed and you don't process basically

00:45:20
Do you want to turn all your tests into imposter the way people achieve this this day? I mean it that they don't realize that but they use Docker for the integration tests. So they have the environment because the backup is very difficult. Right? So that being vitamin to take they make sure all the balance is a properly said I'm just out of the container, right and they did on the integration tests like that, which is great, but it's not use incense that you cannot I-10 to write my infrastructure court so that I can test it in process that I mustn't think you would think of that is cheating. I didn't want to say that I would rather do that than not doing digression test because to set up the proper environment is difficult, especially if you were I mean it could be difficult it is I don't want to call the chicken. I think it's a good approach. I thought it would compromise a couple of students say, oh, well, you know, I've got this class.

00:46:20
And I want to test that I need to mock yet. So I made all the member functions virtual so that I can do you know derived from it and you know to the mocking kind of interface with it and I respond to them and I say I am not an expert in testing methodologies, but that doesn't feel right to me. If that's the only reason you a virtual function is 1 equal marks a evil and I know I would not do that. No, I would do that when I need to win my cloth with said it turns and that her condition in which is difficult to Dubuque, IA by providing input example, if you are passing to database engine valid SQL statement, you probably not going to get connection at all. Right. How do you stimulate connection that I so in that sense? If you have like some Klein for the database and you want to see me like connection that and see how you're cool. You're the actual cordless pontoon marking is great.

00:47:20
Mocking is also good when you have external dependency don't control it and you don't want to bring the whole environment the uprights you break your external depends Market, okay acceptable and also even if you don't have external dependencies, but when you have complex interactions, like really complicated which requires very complex it off and between like two subsystems. So you can lock in the subsystem. Right? Just okay, that's that's acceptable if not asked okay.

00:47:51
The other thing that kind of you know concerns me for it for lack of a better word when I think about mocking and dependency injection as ice go. Well, it feels like now I'm testing something different. Like I'm not testing the actual system. I'm testing the Mach system errors and it all makes sense to me. But I'm just curious. Is that ever been a problem. Have you ever gotten down the road and then go. Oh, no my mock actually gave me a false sense of security somehow for errors know and for the penis injection just one look like maybe slightly correctly. I'm not sure if I understood you correctly when you use dependency injection the way I described it by placing the actual protocol for sale cheap AP winning memory implementation. You are actually testing your whole system. That's the whole point because you are executing the court.

00:48:51
The other side which would be executed on the server side like you are doing and to and that's the whole point of it operating system. Should you test with the actual to D&D Beyond component? I'd like you instead of doing it been since yesterday actually test for the interface which Implements of course patient ask that you play simple, but they are a little slow water on right you have to have an environment, right? So you try to make you fast and easy designs for testing it will drive you design and it's going to get extremely stable system. I work in the lot of different projects right eye I speak from Mostly from my experience than from like Academia experience. So when you do things over and over again, right and you could work and production and it's easy to maintain and I

00:49:51
I just told you the real story write I will not accompany a ride but like I said happened but I stole the real story you seem like you must be doing something right and then why not to share it with World sure my point is that in my previous experience? Yes. I did not write unit tests. I think I want to ask you. When was the first time you wrote the unit? That's I'm actually interested. Like when was the actual first time you wrote the first unit. Well, so I will say a script that that project was the first one that I worked on that actually had tests. So I will say you in my defense but also on my way, I'm not putting you on the spot but also also to conduct myself in a sense. I didn't even write the first test my cousin who is working on the project with me is the one who wrote the first tattoos like we need to have chest on like that sounds like a good idea. So go ahead and do that testing thing right? Like I wasn't used to this at all.

00:50:51
Install stroke bike Allison Raskin someone mentioned like the unit tests were created for antiplatelet interpreted type of languages because like c-plus plus gives you static. That's true. Maybe. But I think you need to use a full across Dino. And in fact, I think they do drive you design like you or whatever you do think. Is it easy to test on if it's not easy to test a red flag. Your components is not properly design. Your right across is a car to test. Yes wrong design easy to test. Yes. Probably you did a good job.

00:51:35
Do you mind if I quote you in the testing section on my C plus plus book I will send you those principles.

00:51:45
Okay, go ahead. It's funny because I've got in the back of my mind that I wrote yesterday that I'm like this code is being used everywhere. So I know that it's tested and it is a strongly typed in her face, but I should probably go ahead and write a unit test for it. I wasn't thinking about if that particular function. So yes, I'm going to do that when we got off the call function function. That's probably the same name least one maybe more depending on the corner cases in the complexities. I feel like I'm seeing, you know, kind of like a complete picture that you from what I'm hearing from you cuz you like you said at the beginning that people get caught up in these different terminologies and it sounds to me like you're in a way saying test at every level as much as you can.

00:52:45
I will give you a good example V in my court probably 60% of my sister is at like 100% code coverage then I hope so, he's doesn't mean you you test every quote that is it is it is close to that. Yes, you will never be perfect. It's impossible to know if you are cursed perfectionist, you will never delivered on time. You'll never get but you have to be pragmatic and you have to be disciplined right? That's that's the point. So if you want to look at how much testing course you should be like, he's probably should be 60% of your coach you the best that some like I've someone will say to be even more I will not. I could probably be but I am and I'm at about 50 to 60% So looping back around to where we started with that pole.

00:53:45
34 * Albert is not using you to test if you're one of those it in the listeners and they've been convinced thing to do some unit. Testing. You have any things to point them to to learn a little bit more to get started any any resources you might suggest that would be me to find an open source projects and just good quality open source projects and take a look and how that tested. Also YouTube video strike bunch of YouTube videos that is just plain of stops for me. It was the real life experience right? There is one particular book that I would recommend. It's called clean Court by Unkle Bob. I think I've been around for a long time enough when I read it. I did not delete the section about the unit.

00:54:45
I read it and talk about this when I looked back at the advocating riding if that's before I didn't go out to be just fine. If you could do that do that. But the main thing is testicle make you have to drive your design. If you have difficulty thinking, you can design it's very late software design is extremely extremely difficult right to achieve good quality Court small functions simple, no cycles and test if you do that 80% you there. I just want to if you don't mind mention again that you see you gave some techniques for testing air cases because I'm in my experience. Now, they're more mature developer compared to the the older projects that I started on. It seems to me that the error handling routines are never tested like when I look at code coverage reports with some of the projects I'm involved in I even submitted a test at one point on one project that had an air in it intentionally because I needed to test the air handling routine and that pull request was denied. We don't want

00:55:45
Code with errors in it and arguing and arguing to test framework and I'm like, but we need to test that every every cold baths should be executed in your unit test that's advisable so and you eat it right sometimes by the way, I'm a big fan of exceptions. I see Patrick with no problem in the time and the lake but you have to use exceptions and he said like but the amount of time did you actually prefer a liquid amount of time you have your each statement?

00:56:45
I don't know of a compiler waffle are the fees if you execute off right probably get you do exceptions. It's not going to cause any kind of performance problems. You should probably measure your car before you decide whether use exceptions oil out. Of course, it's been great having you on the show today working listeners find you online. I'm not really socialist far as Facebook and Twitter. I have a I have a LinkedIn and my email you could post it into the notes. I have no problem people in Chanel directly empty know I feel very passionate about what I do. If you find it's a flaws in my velocity, please reach out to me show me. How could it be done better write this is what I always fix my push back up show me but I do have multiple successful projects behind me that are stable that I'm working during production, you know that and then I mean table

00:57:45
So and Jason if you want to mention some of the stuff I can ride in the email in those principles. Just these components is hard to test a properly designed specifically what I want a quote actually that right there. So I will I will do that. Thank you. Thank you. Thank you. Thank you so much for listening. And as we chat about cplusplus love to hear what you think of the podcast, please let us know if we're discussing the stuff you're interested in or if you have a suggestion for a topic love to hear about that to you can email all your thoughts to feedback at CPP cast.com would also appreciate if you can like see to be cast on Facebook and follow sleepycast on Twitter. You can also call me yet or I'll W Irving and Jayson At Last Kiss on Twitter. We also like to thank all our patrons cups for the show through patreon if you'd like to support us some patient and you can do so I patreon.com sleepycast.

00:58:39
Of course, you can find all that info and the show notes on the podcast website CPP cast.com.

00:58:47
Play music for this episode is provided by podcast names.com.

00:00:02
Translate the current page