tag:blogger.com,1999:blog-82480158734615129102024-02-07T06:37:30.102+01:00CeciliaSharpVisual Studio tips & trixCecilia Wirénhttp://www.blogger.com/profile/05533586388164300287noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-8248015873461512910.post-54525043334827426192016-12-31T01:37:00.001+01:002017-09-06T07:18:02.342+02:00Enable Live Unit Testing on project created before VS 2017To be able to run live unit testing in Visual Studio 2017 on projects created with earlier versions of Visual Studio you need to add two nuget packages to your test-projects. Supported testprojects are MsTest, NUnit and xUnit; and they demands different packages.<br />
To add nuget packages right click on your test project and choose <b><i>Manage NuGet Packages</i></b> then pick Browse and search for them.<br />
Projects will continue to work in earlier version of Visual Studio and your build server will not have a problem with this since all they need is located inside the test projects now. You can also remove all previous references to earlier test dll:s in your test projects.<br />
<br />
<h3>
Microsoft Test</h3>
- MSTest.TestAdapter minmium 1.1.4-preview<br />
<div>
- MSTest.TestFrameworks minimum 1.0.5-preview </div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgUkVoyBKI6t9-Awb8URDdXqYcEE16TcjkiMW4c2pyUZnA8Bo1UtWMZFqkZ0XjnvBVV2lA43W10KSkN6A2DaYSOhzdMkP3InXlXj1tfUJ1s6Zxr6q3KSeNxal52r15S7hMLugkIH43tw8/s1600/nuget2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="72" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgUkVoyBKI6t9-Awb8URDdXqYcEE16TcjkiMW4c2pyUZnA8Bo1UtWMZFqkZ0XjnvBVV2lA43W10KSkN6A2DaYSOhzdMkP3InXlXj1tfUJ1s6Zxr6q3KSeNxal52r15S7hMLugkIH43tw8/s400/nuget2.PNG" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5hyphenhyphenmBbci2XllrqUV6QFBvZsthcWCUJ64TbbBgYtJvolcTAnvCi14YeV5gUxdFgefDcLUc_tELaguVEyzApKbbwATu7kosoUJNtEA6JrnVCHnOpQONfRjGhlIw2v-BZ1ssC_zqEEjPIw4/s1600/nuget.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="77" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5hyphenhyphenmBbci2XllrqUV6QFBvZsthcWCUJ64TbbBgYtJvolcTAnvCi14YeV5gUxdFgefDcLUc_tELaguVEyzApKbbwATu7kosoUJNtEA6JrnVCHnOpQONfRjGhlIw2v-BZ1ssC_zqEEjPIw4/s400/nuget.PNG" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<h3>
nunit</h3>
- NUnit3TestAdapter minimum 3.5.1<br />
- NUnit minimum 3.5.0<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZt3XofP46hvunl-RgvSyrFGDRQUQh_r0KM4Dsu7uvCOc9tAb_9je2KnvjoI32BM7ILDSxATbMhaQtc4WwkUl-NowJr95yjVJCDwMnByDZmUe1IMva1yMbFI358D99-ozpfjIKX2-3JVo/s1600/nunit3testadapter.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="45" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZt3XofP46hvunl-RgvSyrFGDRQUQh_r0KM4Dsu7uvCOc9tAb_9je2KnvjoI32BM7ILDSxATbMhaQtc4WwkUl-NowJr95yjVJCDwMnByDZmUe1IMva1yMbFI358D99-ozpfjIKX2-3JVo/s400/nunit3testadapter.PNG" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhy-df1oAXlfq-J2kiy9p3EW8WlWsU5Jtbza6ljyS73Cg9rw0inuENo73MJn0UOU9BpEQPJeQO02v285gXXNtrfVALeok1FehbPbG83-6udMHsdCjJl8yk7xyKZvmVmCNxekIcAM0_nd2k/s1600/nunit.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="43" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhy-df1oAXlfq-J2kiy9p3EW8WlWsU5Jtbza6ljyS73Cg9rw0inuENo73MJn0UOU9BpEQPJeQO02v285gXXNtrfVALeok1FehbPbG83-6udMHsdCjJl8yk7xyKZvmVmCNxekIcAM0_nd2k/s400/nunit.PNG" width="400" /></a></div>
<div>
<br /></div>
<h3>
</h3>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<br /></div>
<h3>
xUnit</h3>
<div>
I havn’t had the option of updating a xUnit test project but according to Microsoft, it should be:<br />
- xunit.runner.visualstudio minimum 2.2.0-beta3-build1187<br />
- xunit minimum 2.0 </div>
Cecilia Wirénhttp://www.blogger.com/profile/05533586388164300287noreply@blogger.com0tag:blogger.com,1999:blog-8248015873461512910.post-75318024461253800472016-12-31T01:37:00.000+01:002017-09-06T06:58:04.161+02:00Live Unit Testing i Visual Studio 2017Would it be nice to, directly in your code see if it are covered by any tests or even better; if what you just changed, broke any test? This is possible in Visual Studio 2017 Professional. Do you have test projects created in earlier version of Visual Studio? Then you need to update some references first: <a href="http://ceciliasharp.blogspot.se/2016/12/enable-live-unit-testing-for-projekt.html">Enable Live Unit Testing</a>
<br />
To start the live testing use the menu <b><i>Test</i></b>
and choost <i><b>Start</b></i> under <b><i>Live Unit Testing</i></b>:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtytWnSnE6i9_0Sz6bmYlwsI7xxX-eHtc8Zp1GKh8FG2W4ZciUlpkw2ZsbPaD-8CvNu1NOBLveQnZm-9-L1IxoC7-pPu4D-aUByq-DF7GlfHeEJ97-54KKr8qOATONS2KKFf7DUOHB4xA/s1600/startLiveUnitTesting.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="195" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtytWnSnE6i9_0Sz6bmYlwsI7xxX-eHtc8Zp1GKh8FG2W4ZciUlpkw2ZsbPaD-8CvNu1NOBLveQnZm-9-L1IxoC7-pPu4D-aUByq-DF7GlfHeEJ97-54KKr8qOATONS2KKFf7DUOHB4xA/s320/startLiveUnitTesting.png" width="320" /></a></div>
The test will run in the background and when it’s done all your code rows will be marked with one out of three symbols:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7EqhKZsSvR18IznGZepMJxvCZzP4i_lVuH3__R8ZHuS-zWkLM50qcnNR3KsW8nIV1pmtJA2IIxcUFD8teXE7vogd-0EMijuGmOGgebZ17G8C4fmQieQrV_QxIDgZ0JKgFrt5cg3HBwvs/s1600/kryss.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7EqhKZsSvR18IznGZepMJxvCZzP4i_lVuH3__R8ZHuS-zWkLM50qcnNR3KsW8nIV1pmtJA2IIxcUFD8teXE7vogd-0EMijuGmOGgebZ17G8C4fmQieQrV_QxIDgZ0JKgFrt5cg3HBwvs/s1600/kryss.PNG" /></a></div>
- This row is associated with at least one failed test.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFcsn4VHxE6SMu1W-rSSxkxTKeCpEMHZYhEl8Svl3jz7u8tUq_og22SfhIGHy2irXTig3lYTpdNLVE-3I61UEcAbGRwR2kWuqDqFTq_3hfDzCGyq4ezYuA1CFHYEpWG9Zl3UY10qQROGg/s1600/bock.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFcsn4VHxE6SMu1W-rSSxkxTKeCpEMHZYhEl8Svl3jz7u8tUq_og22SfhIGHy2irXTig3lYTpdNLVE-3I61UEcAbGRwR2kWuqDqFTq_3hfDzCGyq4ezYuA1CFHYEpWG9Zl3UY10qQROGg/s1600/bock.PNG" /></a></div>
- Every tests that runs this row is approved.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhX5BwkZ3T1HPnWwZU-mUGoFoctPtpl6Kn_k_kv7fueqCsopn7kVEziaMT3rE-fOY1M-X1zrWM8y_kS2240EszZFZ6wdgBWrIroSBZZSiGmG9LD2g3OPGbGWFi6FHcsDfC4PKSRplyFtMw/s1600/streck.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhX5BwkZ3T1HPnWwZU-mUGoFoctPtpl6Kn_k_kv7fueqCsopn7kVEziaMT3rE-fOY1M-X1zrWM8y_kS2240EszZFZ6wdgBWrIroSBZZSiGmG9LD2g3OPGbGWFi6FHcsDfC4PKSRplyFtMw/s1600/streck.PNG" /></a></div>
- This row doesn’t belong to any tests.<br />
<br />
<br />
If you turn on this feature for a project that are completely without tests, you get a result like this::<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH_sldARiFLQUgiACde-UHgRDObX78mu8yxsT-wKeHMx2flwgDaQY82y07R97wXYeNH2POiuYKX0PA6sxpL7C2T8z9orNNbjmFs6jFRGRi7ToHPHY6P2H57O1JZMMdNwZSfoar2RRakcI/s1600/start.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="227" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH_sldARiFLQUgiACde-UHgRDObX78mu8yxsT-wKeHMx2flwgDaQY82y07R97wXYeNH2POiuYKX0PA6sxpL7C2T8z9orNNbjmFs6jFRGRi7ToHPHY6P2H57O1JZMMdNwZSfoar2RRakcI/s320/start.PNG" width="320" /></a></div>
<br />
Then when you start adding test you will get markings on what rows are approved by tests or not. If you continue to add code, your markings will update for your new code directly:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8boOW0TlsgYmh-FOaPXtaWSaZzE7f7NCyqMIdNhlmxQLNmxewHUjVeeuFG8_Dg1UOf1i6synCJOkwuU4qDnR8W8ij-se4NYCRjhixVxDuCO8CbSxy5uNKPZfvyg06xbvWyK-k-RZa2vs/s1600/five.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="302" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8boOW0TlsgYmh-FOaPXtaWSaZzE7f7NCyqMIdNhlmxQLNmxewHUjVeeuFG8_Dg1UOf1i6synCJOkwuU4qDnR8W8ij-se4NYCRjhixVxDuCO8CbSxy5uNKPZfvyg06xbvWyK-k-RZa2vs/s320/five.PNG" width="320" /></a></div>
<br />
<br />Cecilia Wirénhttp://www.blogger.com/profile/05533586388164300287noreply@blogger.com0tag:blogger.com,1999:blog-8248015873461512910.post-2887693333017711372016-12-17T17:08:00.000+01:002017-09-06T06:45:10.890+02:00Nice news in c#7<br />
C#7 is coming together with Visual Studio 2017 and here is my two favorite news.<br />
<h3>
Throw Exception</h3>
<div>
It’s a common thing to control your input parameters to prevent future reference null exceptions before you assign it to a field like this:</div>
<pre class="brush: csharp; ruler: true; gutter:true; toolbar:false; auto-links:false">if (person == null)
{ throw new ArgumentException("Person can't be null"); }
_person = person;</pre>
But now you can do it like this:<br />
<pre class="brush: csharp; ruler: true; gutter:true; toolbar:false; auto-links:false">_person = person ?? throw new ArgumentException("Person can't be null");</pre>
<h3>
Out variables</h3>
<div>
When we use a function that demands an out variable it’s common that half the times we don’t even care about that value when the function returns, but we do have to be nice and declare that variable before calling that function. Like this::</div>
<pre class="brush: csharp; ruler: true; gutter:true; toolbar:false; auto-links:false">int i;
var isNumber = int.TryParse(s, out i);</pre>
Now i c#7 we can declare inside the function call:<br />
<div>
<div>
<pre class="brush: csharp; ruler: true; gutter:true; toolbar:false; auto-links:false">var isNumber = int.TryParse(s, out int i);</pre>
</div>
</div>
Cecilia Wirénhttp://www.blogger.com/profile/05533586388164300287noreply@blogger.com0