-
Notifications
You must be signed in to change notification settings - Fork 0
What Should I Test? #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
fb176b5
0e3228c
c418cad
740ee3f
b75a608
e0dcd6f
68d8d10
c2c43e6
226556b
23365a1
b4762be
7ac2f72
1dbf4e1
2ddc881
477cf58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using WhatShouldITest.Interfaces; | ||
| using WhatShouldITest.Utilities; | ||
|
|
||
| namespace WhatShouldITest.Entities | ||
| { | ||
| public class Menu | ||
| { | ||
| private readonly IMenuItemProvider _menuItemProvider; | ||
|
|
||
| public Menu(IMenuItemProvider menuItemProvider) | ||
| { | ||
| _menuItemProvider = menuItemProvider; | ||
| DailySpecial = MenuUtilities.GetDailySpecial(DateTime.Now.DayOfWeek); | ||
| } | ||
|
|
||
| IEnumerable<MenuItem> Items { get; } | ||
| public string DailySpecial { get; } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| namespace WhatShouldITest.Entities | ||
| { | ||
| public enum MenuCategory | ||
| { | ||
| Appetizer, | ||
| Soup, | ||
| Salad, | ||
| Entree, | ||
| Dessert, | ||
| Drink | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
|
|
||
| namespace WhatShouldITest.Entities | ||
| { | ||
| public class MenuItem | ||
| { | ||
| public string Name { get; set; } | ||
| public string Description { get; set; } | ||
| public decimal Price { get; set; } | ||
| public MenuCategory Category { get; set; } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using System.Collections.Generic; | ||
| using WhatShouldITest.Entities; | ||
|
|
||
| namespace WhatShouldITest.Interfaces | ||
| { | ||
| public interface IMenuItemProvider | ||
| { | ||
| IEnumerable<MenuItem> GetMenuItems(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using System; | ||
| using System.Linq; | ||
|
|
||
| namespace WhatShouldITest.Utilities | ||
| { | ||
| public static class MenuUtilities | ||
| { | ||
| public static string GetDailySpecial(DayOfWeek dayOfWeek) | ||
| { | ||
| var _dailySpecials = new[]{ | ||
| new {DayOfWeek = DayOfWeek.Monday, | ||
| Special = "Half price tacos!" }, | ||
| new {DayOfWeek = DayOfWeek.Tuesday, | ||
| Special = "50 cent wings"}, | ||
| new {DayOfWeek = DayOfWeek.Wednesday, | ||
| Special = "2-for-1 Desserts"}, | ||
| new {DayOfWeek = DayOfWeek.Thursday, | ||
| Special = "5$ Burgers"}, | ||
| new {DayOfWeek = DayOfWeek.Friday, | ||
| Special = "All you can eat ribs" }, | ||
| new {DayOfWeek = DayOfWeek.Saturday, | ||
| Special = "Special Brunch" }, | ||
| new {DayOfWeek = DayOfWeek.Sunday, | ||
| Special = "Sunday, funday"} | ||
| }; | ||
|
|
||
| return _dailySpecials.Where(s => s.DayOfWeek == dayOfWeek) | ||
| .Select(s => s.Special) | ||
| .First(); | ||
|
Comment on lines
+27
to
+29
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here it is. In the This is the logic that should be tested. Where the predicate is. |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netcoreapp3.1</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| Feature: TestAddingNumbersWithVariables | ||
| In order to avoid writing a lot of extra testing code | ||
| I want to be able to use variables in my SpecFlow tests | ||
|
|
||
| @mytag | ||
| Scenario: Add 1 and 2 | ||
| Given I have the numbers 1 and 2 | ||
| When I add them together | ||
| Then they should add up to 3 | ||
|
|
||
| Scenario: Add 3 and 4 | ||
| Given I have the numbers 3 and 4 | ||
| When I add them together | ||
| Then they should add up to 7 | ||
|
|
||
| Scenario: Add 101 and 1332 | ||
| Given I have the numbers 101 and 1332 | ||
| When I add them together | ||
| Then they should add up to 1433 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test we've written is actually testing line 15 in the code above. The only thing that is happening in this line is an assignment. We're just testing that the .NET assignment operator is working. We don't need to test that. If that's not working, we are going to be having MUCH larger problems. We don't need to cover this line. There is only one path this code can take. There is no branching logic.
Some folks would say that we could rewrite the test to ensure that the CORRECT special is being stored, but this isn't the place for that. The predicate isn't here. Where is it?