Nunit Test naming convention sample
up vote
0
down vote
favorite
Started programming, I am looking at some unit test naming convention: This is a popular one.
MethodName_StateUnderTest_ExpectedBehavior
https://dzone.com/articles/7-popular-unit-test-naming
If I have a Class ParseVendorSupply,
What would I name the first unit test?
FromCsv_ParseCorrectly_IsGood
What would I name the second unit test?
FromCsv_ParseCorrectly_IsIncorrect
//Electronics store
public class ParseVendorSupply
public VendorSupply FromCsv(string csvLine)
string values = csvLine.Split(',');
VendorSupply vendorsupply = new VendorSupply();
vendorsupply.VendorId = Convert.ToInt16(values[0]);
vendorsupply.ProductId = Convert.ToInt16(values[1]);
vendorsupply.Quantity = Convert.ToInt16(values[2]);
return vendorsupply;
public class ParseVendorSupplyTest
ParseVendorSupply parseVendorSupplytest = new ParseVendorSupply();
[Test]
public void FromCsv_ParseCorrectly_IsGood()
string csvLineTest = "5,8,3";
VendorSupply vendorsupply = parseVendorSupplytest.FromCsv(csvLineTest);
Assert.AreEqual(5, vendorsupply.VendorId);
Assert.AreEqual(8, vendorsupply.ProductId);
Assert.AreEqual(3, vendorsupply.Quantity);
[Test]
public void FromCsv_ParseCorrectly_IsIncorrect()
string csvLineTest = "5,testdatatype,3,testextrawords";
VendorSupply vendorsupply = parseVendorSupplytest.FromCsv(csvLineTest);
Assert.AreEqual(5, vendorsupply.VendorId);
c# .net-core nunit
add a comment |
up vote
0
down vote
favorite
Started programming, I am looking at some unit test naming convention: This is a popular one.
MethodName_StateUnderTest_ExpectedBehavior
https://dzone.com/articles/7-popular-unit-test-naming
If I have a Class ParseVendorSupply,
What would I name the first unit test?
FromCsv_ParseCorrectly_IsGood
What would I name the second unit test?
FromCsv_ParseCorrectly_IsIncorrect
//Electronics store
public class ParseVendorSupply
public VendorSupply FromCsv(string csvLine)
string values = csvLine.Split(',');
VendorSupply vendorsupply = new VendorSupply();
vendorsupply.VendorId = Convert.ToInt16(values[0]);
vendorsupply.ProductId = Convert.ToInt16(values[1]);
vendorsupply.Quantity = Convert.ToInt16(values[2]);
return vendorsupply;
public class ParseVendorSupplyTest
ParseVendorSupply parseVendorSupplytest = new ParseVendorSupply();
[Test]
public void FromCsv_ParseCorrectly_IsGood()
string csvLineTest = "5,8,3";
VendorSupply vendorsupply = parseVendorSupplytest.FromCsv(csvLineTest);
Assert.AreEqual(5, vendorsupply.VendorId);
Assert.AreEqual(8, vendorsupply.ProductId);
Assert.AreEqual(3, vendorsupply.Quantity);
[Test]
public void FromCsv_ParseCorrectly_IsIncorrect()
string csvLineTest = "5,testdatatype,3,testextrawords";
VendorSupply vendorsupply = parseVendorSupplytest.FromCsv(csvLineTest);
Assert.AreEqual(5, vendorsupply.VendorId);
c# .net-core nunit
Welcome to Stack Overflow. As this is more of a code review question rather than a specific coding problem you would be better asking this question on the Code Review website.
– Simply Ged
Nov 12 at 1:29
1
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.
– Nkosi
Nov 12 at 2:04
There is no "correct" here, this is good answer but really it can be summed up with "Make a convention that is clear... (to)...you and any teammates who work in the code. Nobody else needs to agree."
– Liam
Nov 12 at 12:02
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Started programming, I am looking at some unit test naming convention: This is a popular one.
MethodName_StateUnderTest_ExpectedBehavior
https://dzone.com/articles/7-popular-unit-test-naming
If I have a Class ParseVendorSupply,
What would I name the first unit test?
FromCsv_ParseCorrectly_IsGood
What would I name the second unit test?
FromCsv_ParseCorrectly_IsIncorrect
//Electronics store
public class ParseVendorSupply
public VendorSupply FromCsv(string csvLine)
string values = csvLine.Split(',');
VendorSupply vendorsupply = new VendorSupply();
vendorsupply.VendorId = Convert.ToInt16(values[0]);
vendorsupply.ProductId = Convert.ToInt16(values[1]);
vendorsupply.Quantity = Convert.ToInt16(values[2]);
return vendorsupply;
public class ParseVendorSupplyTest
ParseVendorSupply parseVendorSupplytest = new ParseVendorSupply();
[Test]
public void FromCsv_ParseCorrectly_IsGood()
string csvLineTest = "5,8,3";
VendorSupply vendorsupply = parseVendorSupplytest.FromCsv(csvLineTest);
Assert.AreEqual(5, vendorsupply.VendorId);
Assert.AreEqual(8, vendorsupply.ProductId);
Assert.AreEqual(3, vendorsupply.Quantity);
[Test]
public void FromCsv_ParseCorrectly_IsIncorrect()
string csvLineTest = "5,testdatatype,3,testextrawords";
VendorSupply vendorsupply = parseVendorSupplytest.FromCsv(csvLineTest);
Assert.AreEqual(5, vendorsupply.VendorId);
c# .net-core nunit
Started programming, I am looking at some unit test naming convention: This is a popular one.
MethodName_StateUnderTest_ExpectedBehavior
https://dzone.com/articles/7-popular-unit-test-naming
If I have a Class ParseVendorSupply,
What would I name the first unit test?
FromCsv_ParseCorrectly_IsGood
What would I name the second unit test?
FromCsv_ParseCorrectly_IsIncorrect
//Electronics store
public class ParseVendorSupply
public VendorSupply FromCsv(string csvLine)
string values = csvLine.Split(',');
VendorSupply vendorsupply = new VendorSupply();
vendorsupply.VendorId = Convert.ToInt16(values[0]);
vendorsupply.ProductId = Convert.ToInt16(values[1]);
vendorsupply.Quantity = Convert.ToInt16(values[2]);
return vendorsupply;
public class ParseVendorSupplyTest
ParseVendorSupply parseVendorSupplytest = new ParseVendorSupply();
[Test]
public void FromCsv_ParseCorrectly_IsGood()
string csvLineTest = "5,8,3";
VendorSupply vendorsupply = parseVendorSupplytest.FromCsv(csvLineTest);
Assert.AreEqual(5, vendorsupply.VendorId);
Assert.AreEqual(8, vendorsupply.ProductId);
Assert.AreEqual(3, vendorsupply.Quantity);
[Test]
public void FromCsv_ParseCorrectly_IsIncorrect()
string csvLineTest = "5,testdatatype,3,testextrawords";
VendorSupply vendorsupply = parseVendorSupplytest.FromCsv(csvLineTest);
Assert.AreEqual(5, vendorsupply.VendorId);
c# .net-core nunit
c# .net-core nunit
edited Nov 12 at 17:34
asked Nov 12 at 1:25
JoeThomas
677
677
Welcome to Stack Overflow. As this is more of a code review question rather than a specific coding problem you would be better asking this question on the Code Review website.
– Simply Ged
Nov 12 at 1:29
1
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.
– Nkosi
Nov 12 at 2:04
There is no "correct" here, this is good answer but really it can be summed up with "Make a convention that is clear... (to)...you and any teammates who work in the code. Nobody else needs to agree."
– Liam
Nov 12 at 12:02
add a comment |
Welcome to Stack Overflow. As this is more of a code review question rather than a specific coding problem you would be better asking this question on the Code Review website.
– Simply Ged
Nov 12 at 1:29
1
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.
– Nkosi
Nov 12 at 2:04
There is no "correct" here, this is good answer but really it can be summed up with "Make a convention that is clear... (to)...you and any teammates who work in the code. Nobody else needs to agree."
– Liam
Nov 12 at 12:02
Welcome to Stack Overflow. As this is more of a code review question rather than a specific coding problem you would be better asking this question on the Code Review website.
– Simply Ged
Nov 12 at 1:29
Welcome to Stack Overflow. As this is more of a code review question rather than a specific coding problem you would be better asking this question on the Code Review website.
– Simply Ged
Nov 12 at 1:29
1
1
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.
– Nkosi
Nov 12 at 2:04
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.
– Nkosi
Nov 12 at 2:04
There is no "correct" here, this is good answer but really it can be summed up with "Make a convention that is clear... (to)...you and any teammates who work in the code. Nobody else needs to agree."
– Liam
Nov 12 at 12:02
There is no "correct" here, this is good answer but really it can be summed up with "Make a convention that is clear... (to)...you and any teammates who work in the code. Nobody else needs to agree."
– Liam
Nov 12 at 12:02
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
What you are doing is perfectly good. (I'll make one suggestion below.)
As noted, there is a lot of room for opinion here. But that leads me to this answer...
Make a convention that is clear and understandable by those who need to understand it. That's you and any teammates who work in the code. Nobody else needs to agree. But also, think about your "future self" wanting to understand as well.
Also, if you decide to change, then just do it. There is no need for consistency across files if you have made it easy to understand. So don't go back and change other files just for consistency. Don't make rules, create patterns that arise out of your own individual actions.
One point regarding the convention you have tentatively adopted. You seem to be making the second and third components be about the same thing. If that's the case, they are redundant and you shouldn't use both. Alternatively, make the second be about the condition that gives rise to the result of the third. For example
FromCsv_WhenWellFormed_ParsesCorrectly()
FromCsv_WhenBadlyFormed_GivesError()
However, if it were me, I would probably drop the third part entirely since it's obvious what the result should be when the data is well- or badly formed.
If desired, you could have more than one badly formed (or even well-formed) test, using different names. Alternatively, make the correct and incorect tests into test cases providing the data as a parameter.
gave points and accepted answer, feel free to thumbs up question also, thanks
– JoeThomas
Nov 12 at 17:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254918%2fnunit-test-naming-convention-sample%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
What you are doing is perfectly good. (I'll make one suggestion below.)
As noted, there is a lot of room for opinion here. But that leads me to this answer...
Make a convention that is clear and understandable by those who need to understand it. That's you and any teammates who work in the code. Nobody else needs to agree. But also, think about your "future self" wanting to understand as well.
Also, if you decide to change, then just do it. There is no need for consistency across files if you have made it easy to understand. So don't go back and change other files just for consistency. Don't make rules, create patterns that arise out of your own individual actions.
One point regarding the convention you have tentatively adopted. You seem to be making the second and third components be about the same thing. If that's the case, they are redundant and you shouldn't use both. Alternatively, make the second be about the condition that gives rise to the result of the third. For example
FromCsv_WhenWellFormed_ParsesCorrectly()
FromCsv_WhenBadlyFormed_GivesError()
However, if it were me, I would probably drop the third part entirely since it's obvious what the result should be when the data is well- or badly formed.
If desired, you could have more than one badly formed (or even well-formed) test, using different names. Alternatively, make the correct and incorect tests into test cases providing the data as a parameter.
gave points and accepted answer, feel free to thumbs up question also, thanks
– JoeThomas
Nov 12 at 17:34
add a comment |
up vote
3
down vote
accepted
What you are doing is perfectly good. (I'll make one suggestion below.)
As noted, there is a lot of room for opinion here. But that leads me to this answer...
Make a convention that is clear and understandable by those who need to understand it. That's you and any teammates who work in the code. Nobody else needs to agree. But also, think about your "future self" wanting to understand as well.
Also, if you decide to change, then just do it. There is no need for consistency across files if you have made it easy to understand. So don't go back and change other files just for consistency. Don't make rules, create patterns that arise out of your own individual actions.
One point regarding the convention you have tentatively adopted. You seem to be making the second and third components be about the same thing. If that's the case, they are redundant and you shouldn't use both. Alternatively, make the second be about the condition that gives rise to the result of the third. For example
FromCsv_WhenWellFormed_ParsesCorrectly()
FromCsv_WhenBadlyFormed_GivesError()
However, if it were me, I would probably drop the third part entirely since it's obvious what the result should be when the data is well- or badly formed.
If desired, you could have more than one badly formed (or even well-formed) test, using different names. Alternatively, make the correct and incorect tests into test cases providing the data as a parameter.
gave points and accepted answer, feel free to thumbs up question also, thanks
– JoeThomas
Nov 12 at 17:34
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
What you are doing is perfectly good. (I'll make one suggestion below.)
As noted, there is a lot of room for opinion here. But that leads me to this answer...
Make a convention that is clear and understandable by those who need to understand it. That's you and any teammates who work in the code. Nobody else needs to agree. But also, think about your "future self" wanting to understand as well.
Also, if you decide to change, then just do it. There is no need for consistency across files if you have made it easy to understand. So don't go back and change other files just for consistency. Don't make rules, create patterns that arise out of your own individual actions.
One point regarding the convention you have tentatively adopted. You seem to be making the second and third components be about the same thing. If that's the case, they are redundant and you shouldn't use both. Alternatively, make the second be about the condition that gives rise to the result of the third. For example
FromCsv_WhenWellFormed_ParsesCorrectly()
FromCsv_WhenBadlyFormed_GivesError()
However, if it were me, I would probably drop the third part entirely since it's obvious what the result should be when the data is well- or badly formed.
If desired, you could have more than one badly formed (or even well-formed) test, using different names. Alternatively, make the correct and incorect tests into test cases providing the data as a parameter.
What you are doing is perfectly good. (I'll make one suggestion below.)
As noted, there is a lot of room for opinion here. But that leads me to this answer...
Make a convention that is clear and understandable by those who need to understand it. That's you and any teammates who work in the code. Nobody else needs to agree. But also, think about your "future self" wanting to understand as well.
Also, if you decide to change, then just do it. There is no need for consistency across files if you have made it easy to understand. So don't go back and change other files just for consistency. Don't make rules, create patterns that arise out of your own individual actions.
One point regarding the convention you have tentatively adopted. You seem to be making the second and third components be about the same thing. If that's the case, they are redundant and you shouldn't use both. Alternatively, make the second be about the condition that gives rise to the result of the third. For example
FromCsv_WhenWellFormed_ParsesCorrectly()
FromCsv_WhenBadlyFormed_GivesError()
However, if it were me, I would probably drop the third part entirely since it's obvious what the result should be when the data is well- or badly formed.
If desired, you could have more than one badly formed (or even well-formed) test, using different names. Alternatively, make the correct and incorect tests into test cases providing the data as a parameter.
answered Nov 12 at 12:00
Charlie
6,48411518
6,48411518
gave points and accepted answer, feel free to thumbs up question also, thanks
– JoeThomas
Nov 12 at 17:34
add a comment |
gave points and accepted answer, feel free to thumbs up question also, thanks
– JoeThomas
Nov 12 at 17:34
gave points and accepted answer, feel free to thumbs up question also, thanks
– JoeThomas
Nov 12 at 17:34
gave points and accepted answer, feel free to thumbs up question also, thanks
– JoeThomas
Nov 12 at 17:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254918%2fnunit-test-naming-convention-sample%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to Stack Overflow. As this is more of a code review question rather than a specific coding problem you would be better asking this question on the Code Review website.
– Simply Ged
Nov 12 at 1:29
1
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.
– Nkosi
Nov 12 at 2:04
There is no "correct" here, this is good answer but really it can be summed up with "Make a convention that is clear... (to)...you and any teammates who work in the code. Nobody else needs to agree."
– Liam
Nov 12 at 12:02