Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, August 17, 2017 10:21 AM
I Want to Know how many codes are excuted in visual studio 2017 enterprise
example
int main()
{
* int a=0;*
* if(a==0)*
* {*
* printf("here");*
* }*
else
{
printf("???");
}
* return 0;*
}
i expect Bolded Line is Not excuted ,
All replies (4)
Friday, August 18, 2017 6:33 AM ✅Answered
Hi joeswish,
Glad to see you.
Based on my knowledge, we could analyze code coverage on unit test in Test Explorer.
So, if you want to do code coverage on visual studio 2017 enterprise. Please first write the unit test for the functional method (has input and output, and they have fixed relationship) you want to test in visual studio 2017 enterprise. Then, choose Analyze Code Coverage on the Test menu after ran your unit test code in Test Explorer.
You could refer to this link to get more details about“Using Code Coverage to Determine How Much Code is being Tested”: https://msdn.microsoft.com/en-us/library/dd537628.aspx
>> i expect Bolded Line is Not excuted
Based on your code example, the bold part of course not executed.
And I don’t know what you want to test. I only find a fixed output, no input found. And the main() is a convention entry method. So, this example doesn't count as a functional method.
Thanks for your understanding.
Regards,
Judyzh
Friday, August 18, 2017 7:48 AM ✅Answered
Hi friend,
Thanks for your posting.
To use Code Coverage you need a Test project. (A project under test and a unit test project like in my side):
I will suggest build a Console project which is under test, and a unit test project to test the function as you gave the example above.
In the Console project my code is:
public class Trigonometric
{
static void Main(string[] args)
{
Trigonometric.outputstr(0);
Console.ReadKey();
}
public static void outputstr(int a)
{
if (a == 0)
{
Console.WriteLine("here");
}
else
{
Console.WriteLine("???");
}
}
}
and the test code is just simple like:
[TestMethod]
public void TestMethod1()
{
Trigonometric.outputstr(0);
}
When I run the test I got it in the test explorer, and I could right-click the Testmethod,
choose Analyze Code coverage for selected tests , after you will get the code coverage result, and you click the button:
you will see color displays the coverage of code(with foreground color):
Hope it helps.
Best regards,
Fletcher
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Monday, August 21, 2017 2:05 AM ✅Answered
Hi joeswish,
Thanks for your response.
Unfortunately, there is no that tool in VS2017 for now, but you may Go to Help-> Send feedback -> Provide a Suggestion
Thanks for your understandings.
Bes regards,
Fletcher
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Friday, August 18, 2017 10:03 PM
thanks for reply
actually i want to test my project(MFC - Dialog Base)
in other coverage tool(like code scroll) , tool makes test case automatically, and I just run the test case
so easily reached 100% code coverage
i expect vs2017 ent can provide easy solution like code scoll(dynamic code coverage tool)
but accoding to your reply, VS 2017 can't provide these function,
for coveragage test, i should make unit test manually. ㅠㅠ