Senior Consultant Byron Katz and Consultant Matthew Taylor of Coveros test an open-source timekeeping tool project that their team is working on. Technology stack: Kotlin, JVM, Intellij, Gradle Open source at https://github.com/7ep/r3z
Byron Katz 0:00
Let's go look at our or BDD as we are want to do.
Matthew Taylor 0:06
Sure. Everything's passing right now. So I think everything.
When I checked it out, we probably have a lot ignored.
Byron Katz 0:13
Yeah, we've only got two tests. Currently, we have a capability enter time, that's our happy path. And we can enter six hours with copious notes that they've already entered 24 hours, they cannot enter more time on a new entry. Okay, let's run it
Let me just double check here our commit, currently, yeah, nothing's really changed. And in here, it says, expected - this exception to be thrown, but it wasn't thrown. And that is let's get into this. When we we created a time entry. And it has the day indeed. And wait, this doesn't really do anything, it creates a time entry. But that's all it does.
Matthew Taylor 1:40
That is a great accomplishment.
Byron Katz 1:42
And then when they enter a new time entry for one hour, the system disallows it. So in fact, that should be our little true guy should be recording this stuff. So we'll say true. dot record time, existing time for the day. So we'll record that. And that should be. Let's see how good that is the time entry is going to. Okay, it makes sure that it's....
I wonder if this is true. If the database is 24 hours already for the provided, query minutes recorded, we just get our minutes recorded. Let's take that out. Because that's all the confusing 24 hours, yes. If the time recorded greater than 24 hours throughout the calculate if if the user has is entering in more than 24 hours in a day, that's insane. Okay, so we query the mess recorded given a certain date. And here's what's going to happen if we fail at this. It's going to return zero. And in that case, minutes recorded will be zero and it will be allowed to go in. So what should happen is when we go to query minutes recorded, we shouldn't be returning a long question mark. We should just return a, a long definite if it's not. We don't get something from this. What should we say here? For a given date when we're checking it out? If we find nothing, it may it might mean
Matthew Taylor 4:10
that's valid. It could be a weekend.
Byron Katz 4:13
Yeah, it might legit be zero because they haven't entered anything that day.
Matthew Taylor 4:17
Well, there needs to be a number not yeah, not nothing.
Byron Katz 4:25
So when we run the query, we should probably test this thing to better understand it. What kind of use what kind of testing do we have on this? time recording test? We're mocking it quite a bit. But...
Matthew Taylor 4:44
I think did we like refactor stuff out of being integration tests and just into unit testhood? Or did we create new ones?
Byron Katz 4:57
We have, we have integration tests right here. This one time recording utilities. This is Oh, wait, I'm sorry, we don't have any oh, time entry persistence tests. So this is the only integration test on it. So I'd like to do is test it a little bit by itself. Function if user has not worked on a given day. We return zero as their hours worked that day. So no, no real need to set up anything. But we will, of course, initialize the database, initialize that this query method, it only needs the user and the date. Okay, fine. So we will just pop that in. That's the arrange the act is for a test user. We'll just do that. Then just for a random day in June, where nothing has already been set up, we should get back zero. assert equals zero. How, what do we get back? Time in minutes. A yup, time in minutes. Minutes worked. And then we will say that the string should be a user should be zero, since they didn't work that day. But instead was...Oh, integer zero actual zero. So we'll say zero L. Okay, so that passed. The next one is, if a user has worked on a given day, we return the last eight minutes work that day. We return however many minutes worked that day.
So in that case, we've done some stuff. Oh, and that's actually what we're doing here. We're saying that they worked for 60 minutes that day. And we got that. And this, of course does pass. Now what happens if it fails in some way? If a user what happens if, oh, you know, we should say if a user worked 24 hours in a day, we should get that from minutes worked. And, you know, to do this nicely, we could say we'll just copy this. And we'll actually duplicate this a little bit. So we'll say time 60. And here we'll say time 60 times 10. And then I'll do Time 60 Time. Let's see that's 11 hours so another 13 hours right to do the trick. That takes us up to 24 hours and that way we should get 60 L times 24. We should get 24 hours worked for this day. Okay, that did work. What happens if, if a user worked 24 hours total for work worked eight hours a day. For two days, we should get just a few hours when checking one of those days. So I'm going to say 60 times 8, 60 times eight. But here we're doing a random day in June. And here we're going to a random day in June 2020 plus one, a random plus one. Now we got two different days. We recorded it. And now let's do it. Oh, this actually gonna fail because I have the wrong number of hours in there. But let's correct that and say it's eight. Okay, it failed. And we got we did indeed get 16 hours. Which is not what we expected to get. When we query minutes recorded. We're just checking the user. So let's close everything. Go here, go back. It looks pretty good in terms of general formatting. Let's look into this thing and say, we're user equals that and date equals this and we're going to get the loan that's perfect. We're just going to pass along the date. I'm feeling really good about this. It's just gonna pass isn't it? Did not like that. Had a type of class blah, blah, blah, which is unacceptable. Well, that's true. Let's see where we're passing in. Oh, it should be date dot SQL date. There we go. Let's run it again. There we go. Bam. Just works. Okay. feeling so good about this. Let's just out of curiosity, let's look at our coverage.
Matthew Taylor 13:25
Byron Katz 13:28
Probably better than pretty okay.
Matthew Taylor 13:31
Large swaths of things that aren't unit testable are low and your ORM I kinda just want to ignore it has to be a separate beast.
Byron Katz 13:44
Yeah, I get it I get it. Eventually wonder why take so long to build now. Have to look into this more, okay, 39 tests. And then while I was running that it occurred to me I could have just right clicked and run with coverage. So let's just try that.
Matthew Taylor 14:21
Okay, so every time I did this, it prompted me to like your files are out of date, redo it, and like no matter what, Oh, you didn't get that?
Byron Katz 14:32
I don't know why you're getting that.
Matthew Taylor 14:34
made me rebuild every time. It's like shouldn't you know to rebuild, just just rebuild.
Byron Katz 14:42
Alright, so God, very high coverage. In Coveros authentication, we've not really looked at that. That makes sense. persistence. Micro ORM. Yeah, but other than that, we are looking sweet
Matthew Taylor 14:56
Whatever you just did got us from 0% to seven 5% I believe.
Byron Katz 15:02
Oh, we're probably only not hitting one single item. What are we missing?
Matthew Taylor 15:17
Go up, yeah there - there vow description is not covered.
Byron Katz 15:23
We never test this description. We'll get to it eventually. Okay, well, we're looking really, really good. Let's commit our work. Oh, is our BDD actually working? Because if that's the case, I would love to check in another passing BDD. And I think it did, because we just ran all the tests, so everything should pass. And yeah, Is this true? I mean, did we legit do this? They cannot enter more time on a new entry. When they enter in more, they get, hey, that's awesome. We get this exception.
Matthew Taylor 16:08
Let's make sure. Just because it's been a while, let's make sure we're not fudging it. Because at one point, we just kind of threw that down the line before. Okay. But what if we could also confirm by A inverse case by a happy path? Okay. Right, that that throw that?
Byron Katz 16:26
Yeah. Let's just see they've worked six hours. Let's go ahead and add in a scenario that makes sense. This one, I might not even need description here. A user enters eight hours on one day and eight hours a day, the next on a project will just say on a project. Or no, we'll say we'll say 16 hours on one day and 17 hours the next. Checking that when a user has multiple days that could add up add to more than 24 hours. Everything goes swimmingly. Okay, so we create a time entry, it's 16 times 16. Create time entry 60 times 17. Entry first day entry. Second day. What's the problem here? Did I not complete this properly?
Matthew Taylor 18:14
There we go.
Byron Katz 18:24
So we enter in both of those days, entry first day, entry. Second day, and then we don't care about the first day's status. Let's just,
Matthew Taylor 18:42
you could store them both. And then order them if we want to be really thorough in case sets like false.
Byron Katz 18:48
Oh, store them both and XOR them. Just check to make sure that they're both valid.
Matthew Taylor 18:54
Yeah. I mean, cuz that's what the cert is for. Right? Make sure the status is true.
Byron Katz 19:03
We're checking to make sure that the second time it's entered, it doesn't complain that it's like we should not be getting this complaint. So it should simply proceed like a no thing. Admittedly, though, we've kind of already tested this in the unit tests.
Matthew Taylor 19:21
also very true. Well, I mean, this actually does it in the unit tests market. We have an integration test that does this.
Byron Katz 19:29
Yeah, I think we do. I mean, if a user worked eight hours for two days, we should just get eight hours from checking one of those days.
Matthew Taylor 19:35
Well, let's kill it.
Byron Katz 19:42
I do like to kill tests.
Matthew Taylor 19:45
The only thing better than writing tests is probably deleting them.
Byron Katz 19:52
Okay. All right. So we're we're doing great here. So got our BDD running successfully and added a little piece there to help out now, including the date. Got some new persistence tests. And there we go, all right.
Matthew Taylor 20:19
I'm going to new tomato. So we should try to get a full new BDD case.
Byron Katz 20:26
Working for handling more than more than 24 hours passing. Now, if a user has entered more than 24 hours, cumulatively, in a single day, an exception was thrown. The system dislikes it. I should have said this allows it, but I will. We'll get back to that later on. Okay, the next one, the user cannot enter more than 24 hours a single day. That's true. If we take all this stuff. And...
Matthew Taylor 21:27
Wait, isn't that is that a different test?
Byron Katz 21:30
Oh, there it is. We won't even get I think to this, because when we create the telemetry, in fact, we don't need like much of anything here that are that? Are that? We're just going to say, always, we really need is this. Yeah. And all we're going to say in here is create a time entry. That takes in all that extra time.
Matthew Taylor 22:08
Gotta make a project or use the default.
Byron Katz 22:12
Yeah, what is the default that were?
Matthew Taylor 22:15
And the time needs like a plus one?
Byron Katz 22:24
Here, Where was that?
Here it is. The we don't have a default project. We'll do a create time entry, we'll just take that out, because we're using the default. And here we'll just say that plus one. And just to make it clear, so that we don't have to deal with order of operations.
Matthew Taylor 23:00
I like to trust math.
Byron Katz 23:04
Well, you heard about that whole fiasco, about order of operations actually being different between different parts of the country.
Matthew Taylor 23:11
Yeah, well, well, some parts of the country are wrong. It was it PIMDOS versus JimDOS,
Byron Katz 23:21
what it was Pimdos versus a PEDMOS.
Matthew Taylor 23:25
Well, they're their actual rules. Rules enforced by I don't know who.
Byron Katz 23:39
I'll just go ahead of it in like that. Sort of throws when we now it's gonna throw a different kind of exception. Oh, you know what, let's just run this. Because we always run to see a failure first. And nothing was thrown. Perfect. Okay, let's take a five minute and we'll start up again on the hour. Or not the hour, the 30 minute, mark.
Matthew Taylor 24:08
All right. We'll be back.
Byron Katz 24:25
All right. We are live. Matt, you're back.
Matthew Taylor 25:07
Hello, I am here too.
Byron Katz 25:10
Hey, all right. All right, let me see where we're at here. Yeah, um, so am I connected? Yep. So you want to try getting this one going?
Matthew Taylor 25:33
Sure. Right. Shock to your cursor. I should probably share. That's gonna complicate the stream.
Byron Katz 25:54
I know you don't need to share. In fact, let me stop sharing as well. Go right ahead.
Matthew Taylor 26:25
What's at fault?
Byron Katz 26:34
I'm going to share your screen.
Matthew Taylor 26:44
Oh, yeah, it seems that everywhere down the line, there's no errors thrown yet. Do we want to be doing anything here though? Or do we want to put that in? Only at the database level?
Byron Katz 26:57
I say just at like the time level? Like,
Matthew Taylor 27:02
I mean, it seems pretty reasonable to pretty much here. See what that looks like, actually, to take a peek at another class.
Byron Katz 27:10
I think it's a kind of integration test where we're going to have to get involved. Instead of using the regular plumbing, if we're going to say we're just allowing entering 24 hours in in a single entry from the database layer, which I think is valid.
Matthew Taylor 27:25
Yeah, I mean, well, we I mean, I think here, it probably makes sense to assert that a single entry is also less than or equal to 24.
Byron Katz 27:37
I don't know that we even need to do it as part of the time entry, I would think just the time by itself should do the trick.
Matthew Taylor 27:44
So let's not necessarily do anything here yet. Let's look at time. Okay, easy. We'll just make a second assert here.
Byron Katz 28:46
You know, we can probably chop these comments down a little bit to something more like for the first one, for example, it's already clear that we're saying greater than zero. So we can just say, like, doesn't make sense to be more, it doesn't make sense to be less than zero or something like that.
Matthew Taylor 29:04
To have clear or negative entries
Byron Katz 29:08
Matthew Taylor 29:12
Right here, we'll say...
Byron Katz 29:16
you basically can't have more than 24 hours a day.
Matthew Taylor 29:20
Just say entries do not span multiple days, right? Because that's the root of it. Your entry has to exist in one calendar day.
Byron Katz 29:27
Yeah, yeah. Yeah.
Matthew Taylor 29:37
So we're gonna need to look for this message later. Let's run the test. Again. Just look at what we get. I closed BDD.
Byron Katz 29:45
You're right on it.
Matthew Taylor 29:46
Yeah. So look at the exact wrong error. We do get and steal it. Just gonna be, are we throwing this? Yeah, we're throwing,
Byron Katz 30:07
You're getting an assertion error, but you can always just get that item that value and then in the next one say assert equal that the message received is this. Yeah. What? So what you do is take that as cert cert throws actually gives you a value, the message itself. Yeah.
Matthew Taylor 30:31
That we are also just asking for the wrong thing. So we'll fix that in a second.
Byron Katz 30:43
You're getting the exception, not the message. You're gonna have to get the exception off the message, or the message of the exception.
Matthew Taylor 30:53
Exception. We'll call it x. That's a convention exceptions a keyword. So the only thing I want to change is that is that optional. Can we just do like base? assertion error Java dot Lang assertion? Not Okay. Does that work?
Byron Katz 31:28
I think you would just do assertion error colon colon class dot java. All right. Cool.
Matthew Taylor 31:50
Now ah question I love whoops. Easier has already entered 24. They cannot enter more. This is a user can't enter more than 24 in a day. This is actually user cannot enter more than 24 hours in a single injury. Yeah. Okay. And working? Cool.
Byron Katz 32:15
Let's commit. Oh, let me commit, actually, since I'm doing the committing side.
Matthew Taylor 32:25
Okay, keep control of the screen since I'm probably playing. Right.
Byron Katz 32:30
That sounds fine. Let me take a quick look here looking pretty good. assertion error looks nice. Then the other one the actual time? Yep, there's the assertion time will not allow more than 24 hours for a single day, or single, for an instance, hold on a sec - a single instance of time will not take more than 24 hours. Let's review says there's some complaints. What's the complaint? Oh, let's make that a Val. Because Val is for immutable stuff. So we usually default to that. Now let's commit. Looking good. Okay, back to you.
Matthew Taylor 33:33
All right. Also, I just remembered something. calendar. You can see my full screen, right?
Byron Katz 33:39
You're, you're twitching out your whole stream for your calendar, by the way. Okay,
Matthew Taylor 33:45
This is a holiday. So I'm gonna say no to these aren't gonna happen? And we? I know we were expecting that to be one of our streaming days, because we both totally forgot. It's..
Byron Katz 33:56
Matthew Taylor 33:58
Yeah. We will not be working.
Byron Katz 34:00
It's not work, though.
Matthew Taylor 34:03
But I get to count as work.
All right. Can I enter time, if you're an invalid user? Let's see.
Byron Katz 34:14
Oh, you know what, by the way, we might want to teach, we might want to like, drop down into TDD for that 24 hour piece on the integration side. Because we want we want to call to the database, make sure that database won't allow it either.
Matthew Taylor 34:28
Okay, let's do that.
Byron Katz 34:30
I think that is time entry persistence tests.
Matthew Taylor 34:33
Yeah, we're gonna need the access helper code just in the green chemistry. Shouldn't that be under persistence?
Byron Katz 34:40
Yeah, we can move it in there.
Matthew Taylor 34:47
I didn't work.
Byron Katz 34:48
Oh, you should be good. I think wasn't just asking if you wanted to confirm that. I think you said Okay. Thank you click Cancel. And you might want to run your tests now. To make sure everything's still legit
not just that one, but all of them. Whenever you make a change, like moving a file you always move.
Matthew Taylor 35:10
Okay, so good. Let's run all of our threes.
Byron Katz 35:23
Welcome, good, man. Let me let me commit that one second. Sure. Moving to persistence.
Matthew Taylor 35:36
We have two tests failing earlier.
Byron Katz 35:39
We may have
Oh, wow. Just command. And let me let me test some mindset because it's some reason I thought that was funky. But let me just run the tests over here. Run all tests. Make sure that flu bits is keeping things nice and even on both sides. What? Yeah, it seemed to have like, gotten funky. So it's passing on yours. Like it's it's all all it says
Matthew Taylor 36:13
Two are failing.
Byron Katz 36:14
You know what? It's because your IDE took charge and made changes, but I didn't get them. Because Flewbits didn't dammit flewbits.
Matthew Taylor 36:27
Let's undo that.
Byron Katz 36:34
No, no, don't do It's fine. It's fine. I just don't see here. Is there a way to send all your stuff to the remote if you go to Tools and go to flu bits. But you just want to push everything? Share project publicly? Maybe.
Matthew Taylor 36:52
Now that's I mean, we're on it. Let's look at the fluids tab. I mean, we could disconnect from it and commit things.
Byron Katz 37:11
Flewbits there's a little arrow button what's that do?
Matthew Taylor 37:16
That's an open workspace in browser. I don't know what what didn't get picked up on your end.
Byron Katz 37:36
Go ahead and click stop and play and connect again and see what happens.
Matthew Taylor 37:42
You should too actually might prompt you to grab things and back in.
Byron Katz 37:59
Okay, it's not complaining at all. But a lot of changes were made go ahead and go ahead and try for a little bit share publicly let's just see what happens there's got to be a way to say send all my recent work yeah.
Matthew Taylor 38:25
Weird. did do a thing that just reconnected to the same space. But it did say updated and sent files.
Byron Katz 38:39
I'm gonna try running all tests on my side now. It didn't delete. Okay, this is a mess. On second. Let me see my recent changes. Oh flewbits, what have you done?
Looking at the remote, look at local.
Matthew Taylor 39:39
How do leaders on on the hub do I don't know if that is the place of us lowely peons or not.
Byron Katz 39:52
Matthew Taylor 40:48
Should you be sharing?
Byron Katz 40:51
Yeah, I'll go ahead and share. I don't totally understand what's happened here. But it's like this one didn't come across. assertion error can't record a time entry that has zero minutes.
Matthew Taylor 41:29
And that's what I was saying.
Byron Katz 41:31
Oh, you we're seeing complaints? Yeah. Oh, okay. Good. All right. So everything's fine. We just have failing tests. And that's only because when we go in here, it was supposed to be this. That's all. Okay. I thought all your tests were running fine. Looking good. Now, let's go back to command here and finish moving to persistence. refactoring, well, changing assertion message. Tests. Okay. Let me create a test for you to fulfill the time entry persistence tests, and then you can fulfill it. Okay. Or would you would you rather write the test?
Matthew Taylor 43:05
Which was what we've been doing more of?
Byron Katz 43:11
Yeah, you haven't written the test very recently? I don't think. All right, let me I'll let you control now. And if you wouldn't mind sharing your screen.
Matthew Taylor 43:21
I'm here. Alright, to BDD. Right, where are we trying to do things right now? We're trying to go down the chain of integration tests for this?
Byron Katz 43:43
Time entry persistence test, we're going to run a SQL command against the database, adding in 24 hours in a single entry. And let's see, do we already have that, by the way, this database already? And if we do we have a test? That simply adds 20? No, it would be stopped by the time itself. So that yeah, that's why we have to do it directly to the database.
Matthew Taylor 44:12
The duplicate button
Byron Katz 44:13
Ctrl D, on Windows.
Matthew Taylor 44:16
Man D may be user space spaced out a bit.
Byron Katz 44:36
In order for this to happen, you're gonna have to call SQL code directly
Matthew Taylor 44:43
It'll be messy.
Byron Katz 44:46
Well I mean, the piece that says, query minutes, all that stuff, you're just gonna have to pull that straight in here. And it won't be messy because you're not setting stuff up. See how you're setting stuff up here. We're not doing that. We're going to just call with raw Numbers straight into the database.
Matthew Taylor 45:03
Are you certain we need to do that? I mean, like this will hit it.
Byron Katz 45:07
it's the only way to skip the logic that we've got in front of it protecting it.
Matthew Taylor 45:14
Yeah. Kill this. Think I'm just gonna kill everything this is melted my brain. Oh look at wherever we do it. So we want to steal much of the code executing an answer but want to do it man. Yeah, I was thinking. So I am going to steal this it's a bit of a bother to formulate. And we're going to need a DB helper. So let's call it access, get get color coded? And I think it is what it is.
Byron Katz 46:31
It's good, isn't it? All this complaining?
Matthew Taylor 46:34
It's happy. It's just I thought it would change color. Okay, see, entry doesn't exist like it did there is we need to make it now we don't have the time entry, though. Because we can't make a time entry. So we'll just have to manually make these things. Yeah. So what type is user ID normally? It's just just a one. That'll just be one. Then project ID is also a long one. Let's confirm they do. And this is a end. Okay. So let's do in that case, that's when we do plenty more 60 plus one.
Byron Katz 47:25
May I suggest taking that and pulling out as a variable to name it so that it's crystal explicit?
Matthew Taylor 47:32
I think that makes lots of sense.
Byron Katz 47:39
See, on mine, it's Ctrl V to pull it out into a variable.
Matthew Taylor 47:43
I think we'll have to go to the refactor menu and see what it recommends. Introduce variable control. I think that shift v. Let's try that.
Byron Katz 47:54
It's like shift Apple V or shift Command V or something.
Matthew Taylor 47:59
Oh my. Command. Option B. Yeah. That'll be alright, for..
Byron Katz 48:14
I don't think it's gonna let you start it with Oh, yeah. All right.
Matthew Taylor 48:23
X, what's it? All right, the date is an SQL date, we can find a way to do that.
Byron Katz 48:33
You can just do a string there. Just a simple, right or that.
Matthew Taylor 48:45
And then got a constant for it, then the details dot value is going to be ah.
Byron Katz 48:55
I always find that annoying myself about double quote. stuff.
Matthew Taylor 48:59
When it when the IDE gets in the way of doing.
Byron Katz 49:02
Yeah. Do you want multiple double quotes? Nope. did not want that.
Matthew Taylor 49:09
They're consistently kind of bad again. Say alrighty what's next? Have a query. We probably want to save this something. No, I mean, we're going to assert that this throws an error No, but it's not going to be an error. Let's just do it. First off, let's cert nothing.
Byron Katz 49:33
Well, before you run it, let me set it let me actually solve it.
Matthew Taylor 49:39
Well, I mean, I'm not making it fail yet. So I have to I have to see like whether to do a tiny bit of a delay. I think I understand what it does.
We actually weren't allowed to use that date. Okay, this wasn't acceptable.
Byron Katz 50:13
Oh that would be dot SQL date at the end to get something out of it. Oh, there's no project.
Matthew Taylor 50:53
Alright, let's, let's create a project. Project, which is just the ID, as it doesn't really matter. You have to know its ID in project.
Byron Katz 51:23
When it's the instantiates is starting from scratch. So it'll be one as the first.
Matthew Taylor 51:27
Those kind of convenient, but I'm okay with it.
Byron Katz 51:31
Matthew Taylor 51:33
We're not testing.
Byron Katz 51:34
I mean, you could always when you persist it, it'll give you back the idea that it just generated. So I think you're right, you could just get that and then that
Matthew Taylor 51:48
makes me happier. Hey, this surplus test is no longer just airing out. So now we just need to assert something. We don't really know what assert throws this is this is spotty, but I just want to hand it over with something.
This whole thing. What did we do wrong syntactically?
Byron Katz 52:57
It just doesn't know what a sequel level exception is. All right.
Matthew Taylor 53:07
All right. It's yours.
Byron Katz 53:09
Okay. Resume resume presenting. Okay, you can see my screen. Little bits. There you are. I think it was like SQL runtime exception or something like that. Or maybe not. Anyway. That's weird. Why is it complaining so much?
Matthew Taylor 53:54
It's very angry.
Byron Katz 53:57
It wasn't too angry in yours as I recall.
Matthew Taylor 54:00
No it was all red, strikes again.
Byron Katz 54:05
24 hours and one minute doesn't even. Okay, well, we'll just say SQL exception. Java class, and it lays this thing even in here. assert throws Oh assert throws simply isn't brought in yet.
Matthew Taylor 54:26
We do need to assert dot assert throws over oh no wait, but above we have assert dot assert throws in its anger. Oh, you just imported it changed things. I think that's what happened.
Byron Katz 55:17
What is happening Why is it so complaining? Just for the sake of seeing this thing actually working properly, everything is great. No complaints at all. And then here I say assert dot assert throws expected throwable is a sequel exception dot java class or a class dot java. And then I don't need that part and then in here all I have to do is I don't know why I was complaining. Some little syntactical things have been in the way So, when I run this should fail. Yeah. And it's actually been over 25 minutes, so, I want to take a five minute break.
Matthew Taylor 56:30
Sure. And this is our last segment started to timer All right, shall reconvene I'm fine with like 12 1107 and then work until my stand up. Roughly. I don't know.
Byron Katz 56:50
Got it. See you then.
Matthew Taylor 56:52
We got a short walk now.
Byron Katz 56:54
Yeah. Welcome back for the last short block of our pair programming challenge with Matt Taylor and Byron Katz. To all zero viewers on Twitch.
Matthew Taylor 57:08
Welcome. Today we'll be doxing ourselves. My address follows.
Byron Katz 57:15
Did people not say their full names on twitch? Is that like a thing?
Matthew Taylor 57:20
I get totally depends on who? Some people are more or less public figures.
Byron Katz 57:27
Yeah, I don't think we're gonna be much of public figures with this thing. Are we supposed to like have like pen names or stage names or something during this? Big maybe I'll be a killer killer.
Matthew Taylor 57:41
Okay, killer Katz.
Byron Katz 57:45
Alright. So it should be throwing a sequel exception. So we're just gonna go into...here's what we're gonna do. Let's go to v1 and in here, date not know. So okay. This actually might be difficult. I don't know if I can do this. In Postgres, I can definitely do it. But an h2.
Matthew Taylor 58:26
That's the spirit Byron.
Byron Katz 58:32
Let's see. H2 check constraint. Check, see is greater than 10. Let's see if that actually works. Add constraint. Let's see what we've got in here. Foreign Key check. constraint. Check hours. will say time and minutes. Less than 24 times 60. That can't possibly work, but let's just run it and see what happens. Oh, I think I'm supposed to put a comma in there wasn't I guess not even gonna finish. Yeah. All right. Just put a comma in there. Let's run it again. Didn't like that syntax error. H2 creat table check constraint. Well, maybe I'll maybe, am I supposed to do that. So it says add foreign key, blah, blah, blah. And we have foreign key references, blah. So I just don't need the add. But everything else I'm good. So constraint, test check. constraint check hours. Check. Time in minutes, let's run it again. Oh, my gosh, it passed. I can't believe that. That's just insane. And just for the sake of testing it with some boundary testing. If a user worked exactly 24 hours total and day it should pass. And we'll say here 24. hours. Exactly. And then here, I will say, if a user worked one minute, less than 24 hours total in a day, they should pass 24 to 30 minus one.
Matthew Taylor 1:02:11
But is it right to be doing these directly with SQL now instead of the normal way? Or should we be you know, making entries for those? I guess my to be boundary testing? Yeah.
Byron Katz 1:02:27
Alright, so this one should not throw anything. And this one should not throw anything. Let's just get the result from it introduced local variable result. And we will simply say, assert, equals, let's see what does execute insert return and just just returns like the new ID. So we'll just say in fact, we'll just say assert true, that result is greater than zero. That's all we care about. Really. assert dot assert. True. That's the problem. Why is it complaining? I just misspelled a cert a SS er T, true. Or? Yep. And St. Same here, which again, we will introduce a result. And now everything should pass, run everything. Got a complaint here. We okay, for exactly 24 hours. So the problem, as you know, is that little symbol right there. Let's run our test again. And that's why boundary tests are necessary. Okay. Cool, I didn't even know we could do check in strings. So that's pretty neat. Adding a check on the database to ensure that time is time entries must be less than must be 24 hours or less. I'll just take all that except ensure that Time entries must be less than 24 hours. There we go. Commit three warnings, see what the warnings are. redundant qualifier name, okay? valid point. And back to here commit. And everything went. Okay. So now if we close everything here and go to BDD our tests are looking really good not enter time, if you're an invalid user. Oh, this definitely gets a little bit trickier. I wonder if we went too far with this, like, we can enter time.
Matthew Taylor 1:05:49
I think we went too far.
Byron Katz 1:05:51
We may have gone too far, because the whole concept of an invalid user has a lot of kind of little threads that extend out from it. So yeah, I think that that was a bridge too far, and project invalid. So both of those are gone. And bam, we're looking really good on the BDD. Let's run everything. Oh, look at that. Okay, let's commit that. BDD is complete for entering time. However, still a bit to do for thorough testing. Okay, um, I like that. Now, what we're doing with this is, we are starting, we are laying foundation for, like our practices in the future. So one thing that we have not really included is logging. So we ought to have a little bit of that. In our time recording tests, let's say test function. Creating a time entry, we want that. Yeah, creating a time entry enters a log item. And we'll say we kind of want this based on something else. Let's go look at what's out here. Concrete project, Java de blah, blah, blah. Let's look at our time recording utilities. What do we have in here, create a project is valid project record time. What kind of test do we have on that right now? Record time for someone. Okay. Make default time entry. Record time result is that's expected result that should be... Okay, we'll just copy this. And instead and here we're going to say we don't really want the result from this. What we want is log.
Matthew Taylor 1:09:19
Not that log.
Byron Katz 1:09:24
Ok we don't work expected result is. Now I'll take that out. Accessing the log is frequently a little bit tricky, so that's why it's gonna be a little bit hard at this very first time we're doing this but basically what we want is logging Get log for library nerd I'm sorry, time recording utils. And that will we'll assume that's a list. Let's see logs is a list of string. And then we will assert. assert true. Expect to see an entry about recording time. logs contains a new time entry was recorded with this info FUBAR. Let's see what I've changed. Alright, let's just commit this. Creating tests to check logging. Commit. And back to you.
Matthew Taylor 1:11:53
I don't think we're gonna get very far in two minutes.
Byron Katz 1:12:01
Or you want to present?
Matthew Taylor 1:12:03
I'm going in, what can we actually accomplish here? Jump to your cursor. That's not quite working. Can you summon me?
Byron Katz 1:12:16
You're there right now?
Matthew Taylor 1:12:17
Byron Katz 1:12:18
It's line 41.
Matthew Taylor 1:12:20
There it is. Let's go ahead and make it. What the hell. We want to make this somewhere else.
Byron Katz 1:12:44
No this is this is good. It's part of the test. Because what's really happening is that there is a log being entered. Getting the log is part of the test.
Matthew Taylor 1:12:55
Okay, so we'll make a helper here, and we'll put it down with the other helpers.
Byron Katz 1:12:59
Yeah. I thought we had helpers. I think we are a bit disorganized about our helper locations. Although, admittedly, we could put this in our general helpers section at a later date.
Matthew Taylor 1:13:15
I was thinking, well, let's pull both of these down to the moment. Yeah, very bottom. It's gonna do some ASCII art here. Perfect. Let's start. Okay.
Byron Katz 1:13:58
Matthew Taylor 1:14:01
Like a big visual. This probably need some input. No I guess not. What exactly is expected. Logs equal git log for time recording. We've recorded a thing. We want it to log and then we want to be able to fetch it. So like, what we don't even have like a logging object. Like anything. I don't I don't even know how that works.
Byron Katz 1:14:42
Yeah, I don't think we're gonna get particularly far with this, but.
Matthew Taylor 1:14:45
Where do you want the log to be? Where do I want to be looking?
Byron Katz 1:14:51
For for the sake of wrapping this up for today, we could probably just return a simple list in our helper method. Now, and just say to do actually connect to the real logging. But a we have to start entering real logs, which has its own little problem. And B, we have to figure out a way to get those logs from a particular class. By the way, you probably want to get into the habit of using Val whenever possible sort of are.
Matthew Taylor 1:15:26
I'm about to add to it. Because I'm not sure if I can do a list literal.
Byron Katz 1:15:31
No, you can. If you create a Val lists, you can always add to the list, you just do a mutable list instead of a immutable list. It's a matter of the fact that the list that you're pointing at is not changing, you're pointing to the same list the whole time, even though it is changing. I know that's probably confusingly worded. It's like about pointers, you know, pointers, they're not really changing in this case. of mutable list of in lowercase M.
All right, insertion error.
Matthew Taylor 1:16:50
I do think I have to pretty much goright now.
Byron Katz 1:16:52
Cool beans. If if you just stop changing anything, I'm just going to commit that.
Matthew Taylor 1:17:00
Stay connected with little bits, I think.
Byron Katz 1:17:05
Matthew Taylor 1:17:07
Sharing and jumping in. Okay. I will talk to you tomorrow. All right, maybe today. Yes. see ya.
Link to full video in YouTube: https://www.youtube.com/watch?v=XhZ4qBROY6I