[00:00:06] Hi everyone. My name is McKenna Barlow. [00:00:07] I'm a product manager on the .NET tools [00:00:09] team working in the testing space. And [00:00:11] today we're going to talk about what [00:00:12] testing looks like as AI starts to [00:00:14] become a bigger part of how we build [00:00:16] software. [00:00:17] So many of you are probably already [00:00:19] using Copilot to work in a codebase that [00:00:21] you're not familiar with or asking an [00:00:22] agent to make a change that previously [00:00:24] you would have worked through yourself. [00:00:26] And that can definitely save you time, [00:00:27] but ultimately you're still the one who [00:00:30] has to decide whether that code is ready [00:00:31] to merge. [00:00:32] And while AI is making it easier to [00:00:34] produce a change, figuring out whether [00:00:36] that change actually does what you [00:00:38] intended is not necessarily getting [00:00:40] easier at the same rate. And in some [00:00:42] cases now you just got more code to [00:00:43] evaluate in the same amount of time. [00:00:46] So that's why we see testing as becoming [00:00:48] an increasingly important part of AI [00:00:50] assisted development. [00:00:52] Tests let us express what we expect the [00:00:53] code to do in a form that we can [00:00:55] actually run. And they also give an [00:00:57] agent feedback beyond just its own [00:00:58] assessment of the code that it just [00:01:00] wrote. [00:01:01] But for that to help us make better [00:01:02] decisions, we really need to understand [00:01:04] what the results are telling us. [00:01:06] When a test suite is green, it's really [00:01:07] easy to kind of just treat that as [00:01:09] confirmation that a change is correct, [00:01:11] especially if we're moving really [00:01:12] quickly or if we're reviewing code that [00:01:14] we didn't write ourselves. [00:01:15] And the tests might all be passing [00:01:17] without ever checking the behavior we're [00:01:18] concerned about though. [00:01:20] So if we take that green result for [00:01:21] granted, we can really get this false [00:01:23] sense of safety and end up feeling much [00:01:25] more confident without actually having a [00:01:27] good basis for deciding whether to [00:01:29] merge. [00:01:31] So that's something we really need to [00:01:32] watch out for when an agent writes both [00:01:34] the code and the tests because if it [00:01:36] misunderstands a requirement, that same [00:01:38] misunderstanding can actually show up in [00:01:39] both places. [00:01:41] Everything might be passing, but we [00:01:42] still haven't checked what we actually [00:01:43] wanted the code to do. [00:01:45] So we want to help you with that part of [00:01:47] the work too. Being able to generate [00:01:49] tests is useful, especially when it [00:01:51] means that you can add tests that [00:01:52] otherwise you might struggle to find [00:01:53] time to write. But once they're there, [00:01:55] you still need to look at what they're [00:01:57] checking. [00:01:58] And the same goes for tests that you [00:01:59] already have, especially that might have [00:02:00] been passing forever and haven't really [00:02:02] given you much reason to look at them [00:02:03] too closely. [00:02:04] So that's what we're going to work [00:02:05] through in my demo today. We're going to [00:02:07] use AI to add some tests, but we're also [00:02:09] going to go back to the tests that we [00:02:10] started just to see if they're checking [00:02:12] as much as we thought. [00:02:14] Uh and as we go, we're just going to [00:02:15] keep coming back to what the application [00:02:16] is supposed to do and whether the [00:02:18] results give us a good reason to trust [00:02:19] it. [00:02:21] Uh before we get into that, I'm just [00:02:22] going to quickly walk through how all of [00:02:24] this fits into the testing tools that [00:02:26] you already use and the framework and [00:02:28] the platform underneath them, just so [00:02:29] we're starting from the same place. [00:02:32] Place to start [00:02:34] uh is this testing workflow that many of [00:02:36] you have definitely already used. [00:02:37] In Visual Studio, we have the Test [00:02:39] Explorer, which gives you a place to [00:02:41] discover and run tests and to debug them [00:02:43] when you need to understand a failure. [00:02:45] Visual Studio Code also provides Test [00:02:47] Explorer integration through C Sharp Dev [00:02:49] Kit, so you can work with your tests [00:02:51] alongside the .NET code that you work [00:02:53] with in either environment. [00:02:55] Um outside the editor, we have .NET [00:02:57] Test, which provides a command line [00:02:58] entry point for building and running [00:03:00] your tests. You can of course use that [00:03:02] in local development or you can [00:03:03] incorporate it into CI through systems [00:03:05] like GitHub Actions and Azure Pipelines. [00:03:08] So these developer experiences are [00:03:10] really kind of like our bread and butter [00:03:11] at Microsoft. These are the foundation [00:03:14] that all of our testing experiences are [00:03:15] built on. And these definitely remain [00:03:17] important as AI takes on more of the [00:03:19] work uh because you definitely still [00:03:21] need to inspect a test and understand [00:03:23] its result regardless of who wrote it, [00:03:24] whether it was Copilot, my teammate, or [00:03:26] myself. So our goal is to bring [00:03:28] assistance into that workflow without [00:03:30] taking away your ability to investigate [00:03:32] what really happened. [00:03:34] The tools that we talked about so far [00:03:36] help you run your tests and understand [00:03:38] the results, but they still leave you [00:03:40] with the work of writing those tests and [00:03:43] keeping them useful as your code [00:03:44] changes. [00:03:45] That's an area where AI can really help. [00:03:48] And many of you are probably already [00:03:49] using Copilot to write tests alongside [00:03:51] the code that you're working on. In [00:03:53] Visual Studio, we have the Test Agent or [00:03:55] GitHub Copilot testing for .NET, and [00:03:58] this provides kind of a dedicated [00:03:59] experience for generating tests. So in [00:04:02] VS, you can ask to generate tests for [00:04:04] the code that you're working on, and [00:04:06] it'll go and build and run those tests [00:04:07] and use the results to work through [00:04:08] changes. So, this is really nice because [00:04:10] it saves you some of that back and forth [00:04:12] involved in getting tests written and [00:04:14] running, but it still leaves you in [00:04:16] control of reviewing what it produced [00:04:17] is. [00:04:18] And that review is still super [00:04:19] important. You know, the agent can go [00:04:21] and check whether the tests compile and [00:04:22] pass, but you still need to consider [00:04:24] whether they're testing the behavior [00:04:25] that you actually care about. [00:04:27] So, we want to make that work easier [00:04:29] too, rather than just leaving you with a [00:04:31] larger suite and no better understanding [00:04:33] of what it covers. [00:04:35] So, that's part of what we're doing in [00:04:36] the .NET Skills repository. Um, I highly [00:04:38] recommend checking it out if you haven't [00:04:40] already. Our team does have some testing [00:04:42] skills in there that you can use with a [00:04:44] compatible coding agent to basically [00:04:45] give it guidance for a particular [00:04:47] testing task instead of having to uh, [00:04:50] you know, like explain the whole [00:04:51] approach yourself every time you ask for [00:04:52] help. [00:04:53] Uh, the testing plugin also includes a [00:04:55] polyglot test agent, and you can use [00:04:57] that one in VS Code or a Copilot CLI. [00:05:00] So, alongside the dedicated VS [00:05:01] experience, there's also an agent you [00:05:03] can bring into those workflows too. [00:05:05] Um, it can actually draw on all of the [00:05:07] skills in the plugin to help it generate [00:05:09] and improve tests, but you can also use [00:05:10] those skills uh, sort of individually [00:05:12] when you have a specific task in mind. [00:05:15] So, today you're going to see me demo [00:05:16] the assertion quality skill to look more [00:05:18] closely at what our tests are checking, [00:05:20] but there are also skills for [00:05:22] investigating gaps in your tests and [00:05:24] even some for helping you with [00:05:25] migrations and all sorts of great stuff. [00:05:26] So, we're going to come back to this at [00:05:28] the end of my talk just so we can take a [00:05:29] better look at what we have to offer [00:05:30] here. [00:05:33] So, all of these experiences that we've [00:05:34] just talked about rely on the underlying [00:05:37] testing stack. So, whether you're [00:05:39] running tests yourself in Test Explorer [00:05:41] or you're asking an agent to generate [00:05:43] and run them for you, you need something [00:05:44] that defines what a test is and [00:05:47] something that executes it and reports [00:05:48] back what happened. So, our work on AI [00:05:51] AI-powered testing goes hand in hand [00:05:53] with our investment in that foundation. [00:05:55] Um, and there are kind of two parts [00:05:57] worth distinguishing here. We have the [00:05:58] test framework and the test platform. [00:06:01] So, in today's sample, we're going to be [00:06:02] using MS Test as the framework. So, that [00:06:05] attributes that identify our tests and [00:06:07] also the the assertions that we're going [00:06:09] to use to check the expected behavior. [00:06:12] Um it also includes some analyzers that [00:06:14] can catch problems in test code while [00:06:15] we're working uh and has code fixes for [00:06:17] many of those rules. And those checks [00:06:19] are really useful alongside AI [00:06:21] assistance because really they're [00:06:22] looking at different things. Um an [00:06:24] analyzer can flag a test method that [00:06:26] doesn't follow the framework's [00:06:27] requirements, [00:06:29] but a test can follow all of those rules [00:06:31] and still miss the behavior that you [00:06:33] care about. So that's where we need to [00:06:34] bring in the requirements and look at [00:06:36] what the test is actually checking [00:06:37] rather than whether it's just written [00:06:39] correctly. [00:06:41] The other piece here is the platform [00:06:43] which is responsible for hosting test [00:06:44] execution and connecting it to all of [00:06:46] the tools that you use. [00:06:48] So here we have Microsoft Testing [00:06:49] Platform or MTP and this is our modern [00:06:52] investment in that part of the stack. So [00:06:54] we're going to use that with MS Test [00:06:56] today. Um but it's worth putting out [00:06:58] that MTP also supports other frameworks. [00:07:00] So using the platform doesn't inherently [00:07:02] mean you have to change how you author [00:07:03] your tests if you already use a [00:07:05] different framework and you're happy [00:07:06] with that. [00:07:09] Before we jump into the code, it's worth [00:07:11] spending just 1 minute on what MTP [00:07:13] brings to that workflow because there's [00:07:15] actually pretty substantial work [00:07:16] happening underneath the AI experiences [00:07:19] that we're going to show today. [00:07:20] Um with MTP, the platform, the test [00:07:22] platform is embedded in your test [00:07:24] project. So the project itself becomes [00:07:27] an application that you can run and [00:07:28] debug directly without having to use a [00:07:30] separate test running console. Um of [00:07:32] course you can still use the Test [00:07:34] Explorer or .NET Test, but you have [00:07:36] fewer external runner dependencies and [00:07:38] you can go and investigate the test [00:07:39] application using the same .NET tools [00:07:42] that you use for your other code. [00:07:45] This also gives us a common place to [00:07:48] build capabilities that work across [00:07:49] supported test frameworks. So you can [00:07:51] add extensions for coverage or crash and [00:07:53] hang diagnostics uh rather than just [00:07:55] each framework having to provide its own [00:07:57] infrastructure. [00:07:59] And for the local development loop, we [00:08:00] have hot reload which we'll show [00:08:01] shortly. What that means is for [00:08:03] supported edits, you can change the code [00:08:05] and rerun the tests with the same [00:08:07] running process without having to do a [00:08:09] full rebuild and restart. So that [00:08:11] currently works in the console host [00:08:13] rather than Test Explorer. So you're [00:08:14] going to see me launch the test project [00:08:16] directly from Visual Studio. [00:08:18] Um and because the tests run as an [00:08:20] application, MTP can support deployment [00:08:22] models like native AOT when you're using [00:08:24] a compatible framework and extensions. [00:08:27] So alongside helping you generate and [00:08:29] review tests, we are also investing in [00:08:31] how you run them and how we investigate [00:08:33] these results because that feedback loop [00:08:34] matters whether you're the one making [00:08:36] the change yourself or if you're working [00:08:37] with an agent. [00:08:40] So with that foundation in mind, let's [00:08:42] bring it to some code and come back to [00:08:43] the question that we started with, which [00:08:45] is, you know, how much confidence should [00:08:46] we actually take from test results that [00:08:49] we're seeing? [00:08:50] So for this demo, we are using an [00:08:52] intentionally super small and like [00:08:54] really simple .NET application that has [00:08:56] a super straightforward business rule. [00:08:58] Um this is on purpose. It's just so you [00:09:00] can judge the behavior for yourself [00:09:01] without needing a whole lot of [00:09:02] background on the code since we do have [00:09:04] limited demo time. [00:09:05] Um I'm going to first show you MTP's hot [00:09:07] reload support so you can see what that [00:09:08] looks like in Visual Studio. And then [00:09:10] we're going to use the test agent to add [00:09:12] some tests and the assertion quality [00:09:13] skill to examine what our tests actually [00:09:15] verify. [00:09:16] Um as we go, we're going to take a look [00:09:19] at what the results tell us and also pay [00:09:21] really extra attention to where we might [00:09:23] still need to apply our own judgment. [00:09:25] So with that, let's look at the [00:09:26] application and jump into VS. [00:09:30] Okay, so let's say that I've just [00:09:32] inherited this application from someone [00:09:34] on my team and I've not worked in it [00:09:36] before. So before I start changing [00:09:38] anything, I definitely want to get a [00:09:39] sense of what it does. So I'm going to [00:09:41] start with the readme. [00:09:44] So let's jump in here. [00:09:46] Um looks like it's an OR quote app. So [00:09:49] you get some items. Um there's a price [00:09:51] and a quantity for each one and it's [00:09:53] going to work out what the total cost of [00:09:56] the order will be including shipping. [00:09:58] Uh again, we've kept the application [00:09:59] really small for this demo just so we [00:10:00] don't have to spend a lot of time [00:10:02] learning the code before we can talk [00:10:03] about the tests, but I'm going to [00:10:04] approach this in the same way that I [00:10:05] would if I just picked something up at [00:10:07] work. [00:10:08] So the readme has business requirements [00:10:09] here, um which is definitely helpful [00:10:11] because I have something to work with [00:10:12] besides just what the code happens to do [00:10:14] today. [00:10:15] So let's take a look. We see the [00:10:17] business requirements have a quote [00:10:19] contains one or more merchandise lines, [00:10:21] each with unit price and quantity, [00:10:23] non-negative USD. [00:10:25] Um subtotal is the sum times the [00:10:27] quantity. Uh looks like the shipping [00:10:29] rule is worth keeping in mind here. Um [00:10:32] we see if the merchandise subtotal is [00:10:33] $100 or more, shipping is free and [00:10:35] otherwise it's $4.99. Um and then the [00:10:38] total is just the cost of the items plus [00:10:40] whatever shipping applies. [00:10:41] Okay, so this makes sense to me. [00:10:43] Uh let's run it and see what this [00:10:45] actually looks like. [00:10:50] Okay, so this example has two notebook [00:10:52] sets at $24.50 each, [00:10:55] um a desk mat for $26, and a subtotal of [00:10:59] 75. So that gets us below the $100 [00:11:01] cutoff, so we do not have free shipping. [00:11:03] We have $4.99 for a total of $79.99. [00:11:07] Um that math checks out. I think that [00:11:09] looks like what I would expect from the [00:11:10] README, so that looks good. [00:11:13] Uh now the next thing that I would do [00:11:15] before touching any of the code is [00:11:16] definitely to run the tests that are [00:11:18] already here. Um I want to know where [00:11:19] I'm starting from, so if something fails [00:11:21] after I make any changes, I can tell if [00:11:23] it was already failing, right? [00:11:25] So I have 10 tests [00:11:28] and let's see. [00:11:30] Okay, so they're all green. So at this [00:11:31] point I'm feeling pretty good. Um I've [00:11:33] seen the back runs, the example that [00:11:34] I've looked at makes sense, [00:11:36] and the existing tests are passing. So [00:11:38] if I just pick this up, I feel like I [00:11:39] was in a reasonable place to start [00:11:41] making changes, right? [00:11:44] Well, okay, maybe before I get too [00:11:45] comfortable with that, maybe I want to [00:11:47] just sanity check by deliberately [00:11:49] breaking something. Uh you know, if I [00:11:51] make a change that's obviously wrong, do [00:11:52] the tests notice? [00:11:54] So I feel like shipping is probably an [00:11:56] easy place to try that. So let's say I [00:11:58] accidentally started charging everyone [00:12:00] $50 instead of $4.99, I definitely [00:12:03] expect something in the suite to [00:12:04] complain about that. [00:12:06] Um so I'm going to take a look at the [00:12:07] quote calculator. I'm also going to use [00:12:09] this as uh an opportunity to show you [00:12:11] hot reload with [00:12:13] key, because this it makes this kind of [00:12:15] back and forth a little bit easier. So, [00:12:16] rather than stopping and restarting and [00:12:18] building every time, I can just make a [00:12:19] supported edit while the test [00:12:21] application's running. [00:12:22] Go ahead and apply that and then run the [00:12:24] tests again in the same process. So, to [00:12:26] do that, I'm actually going to launch [00:12:27] the test project directly. So, I'm going [00:12:29] to set the test project as the starter [00:12:33] project. [00:12:35] And let's go ahead and see what happens. [00:12:41] Okay. [00:12:42] So, we're starting out green. I'm going [00:12:45] to go ahead and make that shipping [00:12:46] change that I mentioned of getting us to [00:12:50] $50. I'm just going to say $49.99. [00:12:54] Save that and hot reload up and then we [00:12:57] can already see the failures here. So, [00:12:59] it's nice that we've got some failures. [00:13:00] That's what I was hoping to see. [00:13:02] It looks like these tests are checking [00:13:04] the shipping. It expected $4.99 [00:13:06] shipping, actually got $49.99. [00:13:10] So, it's nice to see that it's picked up [00:13:11] the change that I've made. This [00:13:12] definitely gives me a little bit more [00:13:14] confidence in these particular tests [00:13:16] because I've seen them fail when the [00:13:17] shipping change is wrong. But what this [00:13:19] does not tell me is that a whole suite [00:13:20] is checking everything that it should. [00:13:22] But a useful sanity check. [00:13:24] So, let me put that back before I [00:13:26] forget. I feel like $50 shipping [00:13:28] probably will not go over very well. [00:13:31] And hot reload up and we can already see [00:13:33] that they're all passing again. So, [00:13:35] that's really nice that I don't have to [00:13:36] go back and forth. I don't have to [00:13:37] restart the test application. So, that's [00:13:39] what hot reload looks like. I'm going to [00:13:41] get rid of this for now and expand [00:13:43] Visual Studio again. [00:13:47] So, you know, before I change anything [00:13:49] here though, I just want to take a quick [00:13:50] look at what's already here in terms of [00:13:52] tests. [00:13:53] So, going to look at the quote [00:13:55] calculator tests. Looks like we've got [00:13:57] some tests for adding the items, [00:14:00] charging shipping free or charging [00:14:03] shipping, [00:14:05] you know, rejecting some invalid inputs. [00:14:07] So, these definitely look like [00:14:09] reasonable things to check based on what [00:14:11] I've seen in the readme. So, I've had a [00:14:13] look at what the app does. I've run the [00:14:14] existing tests. checked that they [00:14:16] noticed one thing is wrong. The tests [00:14:17] look okay. Um, what I'm going to do [00:14:19] next, actually, is ask the test agent in [00:14:22] Visual Studio to generate some [00:14:23] additional tests just to see what it [00:14:25] comes up with here. [00:14:27] So I am going to [00:14:30] uh go into Copilot Chat and I'm going to [00:14:33] select the test agent from the agent [00:14:35] picker. So this gets us our dedicated [00:14:37] testing agent experience. And I'm going [00:14:39] to put us in autopilot for this session [00:14:41] because I trust Copilot and the context [00:14:43] of this repo and what I'm going to ask [00:14:45] it to do. [00:14:46] So I'm going to give a prompt here that [00:14:48] I'm pasting in so you guys don't have to [00:14:50] watch me type this out. But I'm asking [00:14:52] it to generate some additional tests [00:14:53] here. [00:14:55] Um, and one concern that I often hear [00:14:56] about generating tests with AI is just [00:14:58] that it's going to lock in whatever the [00:15:00] code already does. And I think that's a [00:15:02] pretty fair concern, you know. If the [00:15:04] agent takes the implementation as the [00:15:06] definition of what's right, it can write [00:15:08] a passing test for a behavior that's [00:15:09] actually wrong. And then if someone [00:15:11] fixes that code later, the test is going [00:15:13] to complain. So it's all kind of a mess. [00:15:15] So that 's why I pointed it at the [00:15:16] README. I really want it to look at the [00:15:18] code to understand how to use the [00:15:20] calculator, but use the requirements to [00:15:22] decide what the answer should be. [00:15:24] So I've also asked it to leave the [00:15:26] application code alone and just keep any [00:15:28] failing tests because I do want to [00:15:29] understand any disagreement before [00:15:32] anything gets changed to actually make [00:15:33] that pass. [00:15:35] So that still leaves me with some review [00:15:36] to do. Um, the agent could definitely [00:15:38] misunderstand the requirement. Um, and [00:15:41] you know, in a real project, I might [00:15:42] need to check whether the documentation [00:15:43] is even up to date. I might need to [00:15:44] check with somebody else. Um, but at [00:15:47] least this gives me something to compare [00:15:48] the implementation against rather than [00:15:50] just asking the code whether it agrees [00:15:52] with itself, right? [00:15:55] So you can also see some of how it's [00:15:57] approaching the work here. Um, the test [00:16:00] agent is going and reading the projects. [00:16:04] And these entries here that I see in [00:16:06] Copilot Chat show me that it's loading [00:16:08] these different skills, including some [00:16:11] guidance for running MS Test tests. [00:16:14] Um, I also see test gap analysis, [00:16:17] assertion quality. So it's bringing in [00:16:19] guidance for the framework that the [00:16:20] project actually uses. [00:16:22] Um, so now it's build a project to run [00:16:23] the tests. So let's take a look at what [00:16:25] actually happened um rather than just [00:16:27] taking its word that the generated code [00:16:29] should work, right? [00:16:31] So let's take a look at these tests. [00:16:36] Interesting. Okay, we generated three [00:16:38] tests here and one of them is failing. [00:16:40] So let's take a look at what this is [00:16:42] doing. It says calculate subtotal [00:16:44] exactly at threshold [00:16:47] and it's expecting free shipping, [00:16:50] but it actually got 4.99. So let me [00:16:52] check that against the requirement, [00:16:54] right? Because a failing test doesn't [00:16:55] automatically mean the application is [00:16:57] wrong. [00:16:58] Um, so let's go into the README [00:17:01] and look at that shipping again. [00:17:03] It says shipping is free when the [00:17:04] subtotal is $100 or more. Okay, so the [00:17:08] expectation the test does actually look [00:17:10] right. An order at exactly $100 at that [00:17:13] threshold should qualify for the free [00:17:15] shipping and it got 4.99. [00:17:18] So weird. Let's look on our calculator [00:17:19] and see how we're defining this. You say [00:17:21] shipping is subtotal greater than 100. [00:17:23] Okay, so we found the problem. [00:17:25] We're checking whether the total is [00:17:26] greater than 100, which means that an [00:17:28] order at exactly $100 still gets charged [00:17:30] for shipping. [00:17:32] So obviously I'm going to change this to [00:17:35] greater or equal um so that will match [00:17:38] what the README says, right? And let's [00:17:40] run those tests again and see hopefully [00:17:42] we get all green this time. [00:17:47] Cool. Okay, now they're all passing [00:17:49] including the one that caught this [00:17:50] issue. Um, and the useful thing wasn't [00:17:53] just that the agent gave us more tests, [00:17:56] right? It only added three. Um, but it [00:17:58] actually went and added a case that we [00:18:00] were missing. And that failure led to a [00:18:02] real disagreement between the [00:18:03] implementation and the requirement, but [00:18:05] we still needed to look at both to [00:18:07] decide whether the fix logged in the [00:18:09] test or the application though, right? [00:18:11] Um, so we've just seen how this failing [00:18:15] test can give us some very useful [00:18:16] information once we've checked what it [00:18:18] expected against the requirement, but [00:18:19] now everything's green again. Um, before [00:18:22] I move on, I do want to take a look at [00:18:23] some of the tests that we were relying [00:18:25] on before we generated anything at all. [00:18:27] So now we're going to look at a [00:18:28] different kind of problem. Not a test [00:18:29] that is telling us something is wrong, [00:18:31] but tests that might be giving us a [00:18:33] little bit less assurance than we [00:18:35] originally thought. [00:18:36] So we're going to use the assertion [00:18:37] quality skill to examine what our tests [00:18:39] actually check and whether that's enough [00:18:41] to support the confidence that we are [00:18:42] placing in them. [00:18:44] So I'm going to give Copilot another [00:18:45] prompt here. [00:18:50] Um so this is using the assertion [00:18:52] quality skill from .NET skills that I'll [00:18:53] show you in just a minute here. Um [00:18:56] skills kind of just give the agent [00:18:57] guidance for a particular task. So here [00:19:00] I'm asking it specifically to examine [00:19:01] the assertions, not just checking [00:19:04] whether the tests compile or run. Uh [00:19:06] I've also given it the README again just [00:19:07] because uh whether an assertion is [00:19:09] useful depends on what we're expecting [00:19:11] the application to do. [00:19:12] And I've also asked for the assessment [00:19:15] first because I just want to look at [00:19:17] what Copilot's reasoning is before it [00:19:20] starts changing anything. [00:19:23] Um [00:19:24] okay. [00:19:26] Got a response from Copilot. Let's take [00:19:28] a look. [00:19:33] Okay. Mixed verdict, it looks like. [00:19:36] We have this table that's showing us the [00:19:39] tests, what the assertions establish, um [00:19:42] and what incorrect behavior could still [00:19:43] pass. So this is really useful [00:19:45] information. And just scanning here, I [00:19:48] see a couple that look pretty high [00:19:49] priority. Um [00:19:51] only that a quote is not null. That [00:19:53] seems problematic. [00:19:54] Um and total is greater than zero. Those [00:19:56] definitely seem [00:19:58] not great. [00:20:00] So let's go into those tests and see [00:20:02] what's going on here. Calculate multiple [00:20:04] line sums, prices times quantities. [00:20:06] Okay. [00:20:07] That is this one. [00:20:11] Yeah, okay. This makes sense. So we're [00:20:14] seeing that the test is setting up an [00:20:15] order with multiple items and it [00:20:17] actually calls the calculator here, but [00:20:19] all it's checking is that we got an [00:20:20] object back. [00:20:21] Uh it never checks the subtotal. So you [00:20:23] know, if this calculator messed up and [00:20:25] it forgot to multiply by the quantity or [00:20:27] like left out one of the items or [00:20:29] whatever, this assertion would still [00:20:31] pass as long as it returned a quote. [00:20:33] Um and obviously checking it that [00:20:35] something isn't null can be useful when [00:20:37] that's the behavior that you care about, [00:20:39] but it does not establish what this test [00:20:41] says that it's checking, which is [00:20:42] multiple line sums prices times [00:20:44] quantities. [00:20:46] Um [00:20:47] that other one that said just greater [00:20:49] than zero, I want to take a look at that [00:20:51] too cuz that seems like a pretty weak [00:20:52] assertion. [00:20:54] Calculate paid shipping, add shipping to [00:20:56] subtotal. [00:20:58] Yeah, okay. So, we have a similar issue [00:21:00] here, right? This test says that it's [00:21:02] checking that the shipping gets added to [00:21:04] the subtotal. [00:21:05] The assertion only asks if the total is [00:21:07] greater than zero. Um the items already [00:21:09] cost money, right? So, if we return the [00:21:11] merchandise subtotal and totally forgot [00:21:12] to add shipping, we would still have a [00:21:14] positive number and this test is going [00:21:15] to stay green even if the behavior in [00:21:17] its name was broken. [00:21:19] Um so, this is exactly the kind of thing [00:21:21] that I want help spotting, especially [00:21:23] when I'm picking up a suite that I [00:21:24] didn't write. Um obviously this is a [00:21:27] pretty simple example, but these kinds [00:21:28] of things are easy to miss. Like I can [00:21:30] read the test name and assume that we've [00:21:31] got that behavior covered without [00:21:33] noticing how little the assertion's [00:21:34] actually checking. [00:21:36] So, I'm going to ask Copilot to fix [00:21:39] these for me and strengthen the two [00:21:41] highest priority assertions here. [00:21:45] And so, I'm going to ask it to keep [00:21:47] these scenarios and just improve the [00:21:48] checks cuz we don't actually need [00:21:50] another test method here to make these [00:21:52] useful. We don't need another test. We [00:21:53] just need to make sure that the tests [00:21:56] that we do have here [00:21:58] are checking the things that we think [00:21:59] that they're checking, checking the [00:22:01] things that their name suggests that [00:22:03] they're checking, right? [00:22:05] So, Copilot's going to spin and um [00:22:08] hopefully improve at least those two [00:22:10] tests here. [00:22:13] All right. So, it strengthened the two [00:22:14] tests. Let's look at the get changes to [00:22:15] see what we're working with. [00:22:23] Okay. [00:22:24] Yeah, so now this multiple [00:22:26] test is checking the expected subtotal. [00:22:29] So that's good news. It's actually [00:22:30] verifying the calculation rather than [00:22:31] just the existence of a result. [00:22:34] And let's look at the other one, page [00:22:36] shipping test. [00:22:38] Yeah, so now it's actually checking the [00:22:40] amount that we'd expect after the [00:22:41] shipping is added. So returning the [00:22:43] subtotal on its own is not going to [00:22:44] satisfy it anymore. So that's great. [00:22:46] That's what I was hoping for. And let's [00:22:48] just double check on these tests. [00:22:51] And you know, they're still green. [00:22:53] So of course that's what we'd expect if [00:22:55] the implementation is doing this [00:22:56] correctly, but we've changed what this [00:22:58] green result means, right? Before these [00:23:00] tests could pass without checking the [00:23:02] behavior that we thought that they [00:23:04] covered, but now the assertions are [00:23:06] actually tied to the amounts that we [00:23:07] expect from the requirement. [00:23:09] Of course this does not prove that we [00:23:10] found every weakness in the suite, but [00:23:12] it's giving us a much better basis for [00:23:14] trusting these particular tests without [00:23:16] just adding more of them. [00:23:17] So when I first opened this up, I saw [00:23:20] the app ran and all the tests were green [00:23:21] and I felt pretty good about making a [00:23:23] change, but since then we found a bug [00:23:25] that the existing tests weren't [00:23:26] catching. [00:23:27] We've seen that some of those passing [00:23:28] tests weren't checking what their names [00:23:30] let us to expect. So that's really what [00:23:32] I wanted to show here. [00:23:34] You know, AI can help us add tests and [00:23:36] take closer look at the ones that we do [00:23:38] already have, but we need to bring our [00:23:39] own understanding of what the [00:23:40] application is supposed to do. [00:23:42] The goal isn't just to get them all [00:23:44] green, it's really to have a better [00:23:45] reason to trust that result when we're [00:23:47] deciding to merge. [00:23:49] So before I show you where to find these [00:23:51] skills, I do want to show you how they [00:23:53] can fit into a PR review too, rather [00:23:55] than just only when you're writing the [00:23:57] code. [00:23:58] So I have it here [00:24:01] this PR that one of the engineers I work [00:24:03] with closely in Amari put together for [00:24:05] me. [00:24:06] It's a demo PR that has some [00:24:09] deliberately problematic tests. [00:24:11] There are five of them as you can see [00:24:13] and they all pass when they run [00:24:14] serially, but we put some problems in [00:24:16] here that passing result won't tell you [00:24:18] about. [00:24:19] This repository has quite a few [00:24:21] automated workflows. So there's quite a [00:24:23] bit of feedback going on here, so I'm [00:24:25] just going to scroll past these other [00:24:27] reviews and down to the test quality [00:24:30] review. [00:24:31] Um, and down here, the workflow has used [00:24:35] this grading skill to actually look at [00:24:37] the individual tests. [00:24:39] So each row here is a test. This first [00:24:41] column gives it a letter grade based on [00:24:43] the review's assessment of its quality. [00:24:45] So that's separate from whether it [00:24:46] passed when we ran it. [00:24:48] Um, these notes explain kind of the [00:24:50] reasoning here and some suggestions on [00:24:52] how to improve. [00:24:53] So if we look at the first row, that one [00:24:56] got an F. Um, [00:24:58] looks like it's supposed to check that [00:25:00] when half the tests pass, the percentage [00:25:01] is 50, but it calculates its expected [00:25:04] answer by calling the same function that [00:25:06] it's testing. So really it's just [00:25:08] comparing the function with itself. [00:25:09] Um, and of course bold answers can be [00:25:11] wrong in the same way and the test will [00:25:13] still pass. [00:25:14] So this review flags that and suggests [00:25:17] checking against 50 directly, which [00:25:18] would expose the calculation bug. So [00:25:20] some helpful improvements here. [00:25:22] And then we see we have C, we have two [00:25:24] B's, and the one on the bottom gets an A [00:25:27] because it notes that it does actually [00:25:29] do a specific check for the expected [00:25:32] value that's independent from the [00:25:33] calculation. Um, of course I'm still [00:25:35] going to read the explanation, go take a [00:25:37] look at that test, and decide whether I [00:25:39] agree rather than just treating the [00:25:40] grade as verdict, but now that feedback [00:25:42] is right here in the PR for the author [00:25:44] and reviewer to discuss before merging [00:25:46] instead of just relying on someone to [00:25:48] spot it all themselves. [00:25:49] So now let me show you where you can [00:25:51] find these skills. [00:25:54] So this is the .NET test plugin in the [00:25:57] .NET skills repository, and this README [00:25:59] just kind of walks through the different [00:26:01] tasks that it can help with. [00:26:03] So alongside generating and running [00:26:04] tests, there are skills for examining [00:26:06] assertions like we saw today, um looking [00:26:08] for gaps in what your tests check, [00:26:10] investigating code that's difficult to [00:26:12] test. There's all sorts of good stuff in [00:26:13] here. [00:26:14] Um, we also have the separate test [00:26:17] migration plugin that is linked right up [00:26:19] here. Um, and this is for framework and [00:26:22] platform migrations. So these can help [00:26:24] you get on the most modern test platform [00:26:26] so you can take advantage of some of [00:26:28] these MTQ benefits that we talked about [00:26:30] today. So we'll leave you with the [00:26:32] repository link on the resources slides [00:26:34] so that you can explore what is relevant [00:26:36] to your own projects. [00:26:38] So, coming back to where we started, AI [00:26:39] can definitely help us get a change [00:26:41] written, but we're still the ones who [00:26:43] have to decide whether we're comfortable [00:26:45] merging it. [00:26:46] Today, we've seen how tests can help [00:26:47] with that decision, both when a failure [00:26:49] draws our attention to a problem and [00:26:51] when a passing test turns out to be [00:26:53] checking less than we expected. [00:26:55] Generating tests is certainly useful, [00:26:57] but we don't want to just stop at [00:26:58] getting more tests into the project or [00:27:00] getting the suite green. We really want [00:27:01] to help you understand what those tests [00:27:03] are actually telling you about the code, [00:27:05] whether you wrote them yourself or if an [00:27:06] agent wrote them for you. [00:27:08] So, here I have some links that cover [00:27:10] the test agent in Visual Studio, the [00:27:13] skills that we just looked at, as well [00:27:14] as MS Test and MTP documentation. So, if [00:27:18] you do try any of this on your own code, [00:27:20] please feel free to send us a note and [00:27:22] tell us what worked and what got in your [00:27:23] way. Your feedback definitely helps us [00:27:25] understand what to tackle next and it [00:27:27] makes the tools better for all the work [00:27:28] that you're already doing. [00:27:30] So, with that, that's all I got for you [00:27:31] today. Thanks for joining.