 I'm here with Rocky. Why don't you introduce yourself and tell us what you've been working on, but sure. I'm Rocky Latka I'm the CTO at Magenik and here adding some tests to the toolbox project So that sounds like super easy, but when you're looking at adding tests to a project. It's already existing Sometimes that requires a little retooling. Did you did you have any of that happen? Oh, yeah Testings never actually. No, I know. I'm just saying it sounds easy But if you go to your manager and you're like, hey, we're gonna add some tests They're like that's super easy, but that's not what it is, right? No. In fact, there's you know, a lot of Existing code. So we've got to figure out what the code is doing and then in some cases figure out ways to be able to generate sample data or known data sets and and run through the code and so we've had to Change a few things here and there. Luckily. I've only found one real bug so far today. So that's good So is there is this the case and you tell me if you're going Into a project and there's not some tests Do you find that having to write some tests requires maybe sort of rewriting way the application might be working in order for the test to Work a little bit better sometimes. Yeah. All right. Well, let's take a look at what you've done and see if we can find any of that Sure. So really the project had very limited testing to start with everybody was joking. There was one That's not true. There was three right there were three. That's right and But then I've added some some new ones here so for example, we've got a test that is running through the idea of can we get activity detail and On the surface, you'd say, well, that's that's easy, right? If we look down here, the actual tests are not that hard We basically create a query And then call the handler and then in this case, I expect not to get anything back So I'm saying was it, you know, and all So that was the easy part. But then when you start saying, well, what about the test for something that does exist? Say, well, we do expect to get something back. Okay, fair enough But then there's all this code here because we have to actually have something to get back, right? And And days gone by And I'm sure a lot of people maybe still do this would set up a test database and have some sort of script Every time you run your tests and then re-initialize the data the actual database and you know Why I remember those days So in this case what we've got is we're using entity framework with an in-memory database model I see and So in fact if I go up one level higher And then here's one of the areas where we started refactoring some of this is we've got a base class for the tests that at least sets up some of the base configuration Information and in this case in particular is setting up our entity framework to be in it creates essentially an empty in memory database And and all of this is using dependency injection to pull the appropriate resources just like the app itself does So then back in my actual test class. I'm able to just implement a load test data Method retrieve that pre-existing empty and a framework context and then fill it out fill it up fill it up with then and Here here's an example where the app itself has got a sample data generator So that it's possible to run the website and you know just kind of see some meaningful information But that's really quite large and complex. It's six seven hundred lines of code that creates a complete Working set for somebody to play with right as an end user We want something for tests. That's a lot more focused on what we're really trying to test. I see this is kind of the minimum Set to get an activity in that an activity has to we have to be within a tenant an activity has to be within a campaign And then I can create an activity itself Interesting. So that's like the bare minimum Necessary and then once I've got that into the entity framework context then I can turn around Start pulling it out and call the actual Production code that would pull us back out and make sure that I really got it back And it's important to be clear here that we're not testing any frameworks capability to return data We're testing to make sure that the detail query is and the detail and the detail query handler are doing the right thing Well, and then it's really this Detail query handler that we're primarily testing and because it's got code Sure that does a query against the database or against entity framework And then does some mapping of that information back and we want to make sure and so this test is Really not complete the way that I've got it now All I've got so far is that I make sure I'm getting something back sure I need to Flesh out the test and make sure I'm getting all of the expected values back Okay, so I saw I saw on the test that using the fact attributes are using x-unit. Is that right? Yes? That's why x-unit In my case it was a decision made before I got so that's good. It was easy to make the reason for me This was not a problem. So let's talk a little bit about the tooling and how the tooling is helping you with unit test Is the tooling do anything for you when it comes to unit tests? Well, the tooling Is fairly nice. You know built into visual studio is this idea of the test Explorer and test runners So I'm able to just Run up here and say I'd like to you know run all of my tests We'll do a quick build and if we go back to the test Explorer now. We'll see right across here the Bar I've got one failing test, which I know I'm working on that now. Oh awesome. So I expect that to be failing. I'm not done with it Cool, and then I've got all a set of tests that are running more than three more than three. Nice. We were doing good That's awesome Yeah, this is not my normal view. This looks good for demo purposes sure just to say look at all the red and the green but In practice, I think if you start by class then you start to be able to Zoom in and say well, you know right now what we were looking at was the get activity detail And here's the two tests that exist within that context and looks like they're passing and it looks like those two are passing So in your experience and you've been doing this for a long time Coat coverage is there I know there's not like a you you don't have to hit a hundred percent But you certainly shouldn't be like a twenty percent right what do you what do you feel sort of like a good? Sort of smell for how much should I be testing? I really think It's difficult to narrow down on a specific percentage Certainly, I've worked or interacted with places that are all we want a hundred percent and I don't think that's Effective, I mean yeah, if you can even achieve it you're spending way more money than you should be right Yeah, twenty percent is typically bad pretty pretty bad So you probably want somewhere, you know well north of fifty percent, but I also think that you have to look at what you're testing because there's Code that's a lot more complex or a lot more on the critical path and then there's code That's that's arguably less important your perspective. I've always liked your perspective because you always put it in terms of What's it gonna cost? Well, yeah at the end of the day We're you know unless you're sending something to Mars and the any given little teeny mistake becomes super expensive, right? Yeah, for the rest of us It really is a business decision about just how much do I have to spend to? Build and get this done versus what kind of value am I going to get absolutely because in some cases You're not gonna get test coverage over auto implemented properties if you don't do a test on them And that's kind of a waste of time well certainly yeah, right okay, and yeah, and I think too You know that's that by itself is a good point because if you are one of the organizations that invest heavily in code generation And a lot do sure Then you got to ask yourself well Is there really value in having unit tests not say we shouldn't have tests but unit tests on generated code When you're never gonna fix the code you're gonna fix the generator, right? Right, so if you're gonna test anything you probably want to test the generator to make sure that it's coming up with The results that you're after awesome. So what do you have what kind of work do you have ahead of you? Well boy, we're just really getting started on this testing So we're you know, I've got a flesh out some of the tests that are here and now that we've got a model I think it'll be easier Maybe to get more people involved in writing some more tests on more handlers. Well awesome. Well, I'll let you get to work But great. Thanks. All right. Thanks bud