- Podcasts
- Teaching Python
- Episode 118: Quick Bites: Testing Student Code
Episode 118: Quick Bites: Testing Student Code
Teaching Python
- October 21, 2023
- 15 min
- Episode 118
About this episodeToday, we'll talk about how to test students' code using automated tools. For example, the unit testing built into Replit's Teams for…
Today, we'll talk about how to test students' code using automated tools. For example, the unit testing built into Replit's Teams for Education allows students to see if their code is correct, while teachers can quickly assess dozens of submissions. We'll also talk about potential pitfalls that can disrupt or distract from learning.
Note: This is a shorter episode format that focuses on one specific topic, limited to 15-20 minutes.
Links:
- Teams for Education - Replit — Tests and autograding Save time on grading. Free yourself up for more individual attention and increase student persistence by letting them test code before turning it in.
- PyBites Platform | Real World Python Exercises — Overwhelmed by tutorials? Stop consuming books and courses! The only way to really learn to code is to write a lot of relevant code. Our platform makes you a confident programmer fast.
Transcript
From the publisherThis transcript comes from the podcast’s own feed, as the publisher wrote it. It has no timestamps.
Episode 118: Quick Bites: Testing Student Code
Sean Tibor: Yeah. We're going to try something a little bit different. This is going to be a short episode, a quick stream. Hopefully we'll have a few people join us. But honestly, we're just going to try to pop through a quick topic and make it a regular thing. So every Wednesday night our time, we're going to put together a brief bite sized tip for our listeners that helps them teach or learn a little bit better. So we'll see how this goes. There's no wins of the week. There's no witty banter between us. We're just going to jump right into talking about teaching and talking about a one bite sized topic.
We'll see how it goes. Let me see if I can present. Oh, I can't present unless I share the entire screen. And I have a very big screen going right now. Let's just try this. And Kelly, I'm going to find another way to share screens later. But basically what I wanted to talk today about was automated testing. I've been doing a lot of this at work. I've been doing writing a lot of tests, and I realized how valuable this is for teachers to be able to grade things faster and see if students really got the point of the assignment. But it also occurred to me that this is really valuable for the learners themselves because they can see if they got it right and they can iterate and go through that loop of learning really fast because they can try something, check to see if it works, try something, check to see if it works. And it should make it a lot easier than guessing that you got it right and sending it into the teacher only to find out a week or two later whether it actually works.
Sean Tibor: So when you're writing code for production use or something, you have to make sure is right. Tests are a really important part of that development process because you can verify that everything is working the way it's supposed to. And when you change your code, if it fails, some of the tests that you've written, you know exactly where to go look and what to test. So it's useful on the coding side, but it's also really valuable on the teaching side.
Sean Tibor: Kelly, you have described yourself as being really good at teaching the basics, right, of Python so you are an expert at the basics, which I love. Let's take something really simple. Let's say you're teaching F strings to students, right? And so you want to teach them how to use F strings. And so how would you normally set that up? Like, if you ask them to code something to prove that they know how to use F strings, how would you do that?
Sean Tibor: So when you're talking about automated testing, it's really what is the expected value or what is the expected output? So if they're running this code, you expect to see it print, kelly Paretus is the best teacher in the world, right? So what you do is you create a test for that and say, is the output of this program when you run it, Kelly Paretus is the best teacher in the world. You check to see if the output of the program matches an expected string that you've already created. If it does, then the test passes, right? If it doesn't match, not only can you say, hey, that failed, but you can tell them exactly what failed. Like, it's supposed to say, Kelly Paretus is the best teacher in the world, but what you wrote was, Kelly Paretus is awful, and I don't want to learn from her ever again.
Sean Tibor: Or maybe they put an exclamation point on it when all you wanted was a period, right. So you can check individual characters to make sure that it matches correctly, right. It'll show you the difference. So when you write this as a test and you can write this in replet with their input output testing. You create a little instruction at the end and it's just a match, right. I have it here on my screen and the test is here's, the test name, it's string formatting. It has an input box so you can put your standard in, and it has an expected output where you can type the string that you want.
Kelly Schuster-Paredes: And that would be good in the case, for example, if we were doing the password and username kind of example, you want it to match exactly because it's very important to have the username and the password. And that's something that a lot of people can relate to because that's in everything you right.
Sean Tibor: So you could use the input variables and seed it with the input that you want and then check to see if their program produces the correct output. And we'll come back to that in a minute. It's kind of an important idea. So what this allows the student to do in Replit and in other programs that implement this is that when they go to create the assignment or complete the assignment, they run their program and it tells them right there at that moment, your test passed or your test failed.
Sean Tibor: And then when you, as the teacher, come back and look at this, you can see all of your assignments, all of these assignments passed and all of these other assignments did not pass and why, right? So you can see their code, you can see what the test was. But the other thing that I like about this from a teaching perspective is it causes you as the teacher to think, what do I really expect them to be able to do? What's the outcome of this experience?
Sean Tibor: In this case, it's like I want them to be able to use F strings. I want them to know how it's going to work. Right, so you are thinking more about the outcome of the exercise and less about the rote repetition of just practice 15 different F strings. You're really thinking about what do I, Kelly, want them to be able to do and perform at the completion of this assignment?
Kelly Schuster-Paredes: And that's huge. That's like your standards, right? So I want them to complete conditional statements. I want them to build a function. I want them to do X, Y, and Z. I don't really care maybe about that content or whatever they put in with the sentence. I'm just checking for that concept completion data.
Right. So this Pytest in replet is really great because it's input output. It's the standard input and it's the standard output. So you can use it for those early basics, right, where maybe you haven't taught them about functions yet. You just want them to write some step by step actions right now. There was a point when we were teaching where you were sitting there in class one day and I was teaching functions, and you're like, I get it, I finally get it, I understand. Right? Once they have that moment, or once you get them there with functions, then what you can do, it's kind of like a level up in your ability to teach this. What you can do then is create unit tests. And so a unit test is being able to provide inputs to a function and verify that the outputs of that function match what you expect, right? And this is specifically in Replit, there's some more sophisticated things you can do when you're doing software development. But in Replit, this lets you see did they call this? You can call their function and see if it matches the output that you expected, right?
Kelly Schuster-Paredes: Which is really nice because then they can see that that's one of the hard parts with functions, right? Because they can't really get the concept that it's a stored value or returned value and you would have to reassign it in order to get it, et cetera, et cetera. And that's quite helpful, right?
And so it brings me to one more concept. And this is like, I think, the real bite sized tip here, right? You and I have seen this before, where students, in order to pass the test, will hard code a value, right? So instead of saying using an F string, they'll just write the string that needs to be output and they'll submit it, right? So when you're doing this, write more than one test. Write multiple tests, like with different inputs, and make sure that the different inputs match the expected output, right? At least if they're going to hard code some values in there, make them work for it, like put in an if else statement, right? And I'm sure a lot of the people that are familiar with tests know that you can create synthetic inputs and know what the output will be. So you can generate your own input and calculate what the output should be and then check that it does that. But for this, keep it simple. Do two or three different inputs that they have to handle and the corresponding outputs to verify that they're not just hard coding the string in there to output it or to return it back from their function.
Sean Tibor: What do you want them to practice? What are you having them demonstrate in terms of their knowledge? So make sure that when you're designing these exercises and you're designing the tests that go with them, that they make sense from a learning pedagogical or androgogical output perspective, like, what is the desired outcome? It's not the ability to pass the tests, it's to learn something, to demonstrate the knowledge and the application of that knowledge in a coding environment. If all it was, was just to pass the test, we could probably teach Chat GBT to do that. So try to think about tests that are purposeful, right, that they're relevant and that they cause students to think a little bit about what the true code that they have to write will be. So it's not just something they can put into Chat GPT and say, hey, write me the code for this and I'm off and running.
Kelly Schuster-Paredes: And that's half the battle. Correct? Being able to articulate it, being able to explain it, being able to read what you're writing and know what you want out. If you can get the students at least that far, regardless if they use Chat GPT, at least they're communicating some knowledge in that topic.
Sean Tibor: Exactly. So there's my little bite. Write some tests, use some tests. I know that, for example, Replit has built in automated testing, right? The code challenges from the Pybytes group has built in testing with it, you can even write your own. And there are other testing frameworks where you could take program files from the student and run it through your test battery. So it's not something that's specific to any given platform. And also, it will probably cause you to write better code yourself.
Sean Tibor: Here's our Wednesday teaching tip. So I think what we're going to try to do, and we'll see how this goes, is that I'm going to try to come up with the coding tip of the week, and Kelly's going to try to come up with the teaching tip of the week, and we'll try to make sure that it's crossover relevant for everybody. So see how it goes?
