Unit Testing Typescript In Visual Studio for Angular 2 development - unit-testing

I am new to angular2. Hence we are writing code in Typescript for our website. We are using Visual studio 2013 for the development. Now we need to write Unit Test cases for the Typescript code we have written.
Can someone please share a step by step example on how to configure typescript unit testing in visual studio. And whether should we write unit test cases for typescript in typescript, or we should write unit test cases for typescript in Javascript.
Thanks in advance.

Have you seen this: https://github.com/Steve-Fenton/tsUnit
"tsUnit is a unit testing framework for TypeScript, written in TypeScript. It allows you to encapsulate your test functions in classes and modules."
While this does not provide "step-by-step" directions ... it could be a step in the right direction!

Related

Angular (Typescript) Unit Testing - ASP.Net Core MVC SPA

I am developing a project which started life as an ASP.Net Core MVC SPA Template in Visual Studio 2015. I used the Visual Studio Karma Test Adapter with no problems for my Angular (Typescript) unit testing, but no matter what I tried I could not get NUnit to recognise my C# unit tests for the Web API and early Domain Model code. I tried to add a separate Test Project with no success and I also created unit test files within the same, single, project with no success.
At some point I knew I should migrate the code to Visual Studio 2017, as I feel that the new IDE will prove to be beneficial as the project develops, so I thought I would do it now and see if it solves my unit testing problems. Visual Studio's migration process didn't go well so I decided to start from scratch again.
I ran dotnet new angular to create a clean solution which I opened in VS 2017. It appears that the Visual Studio Karma Test Adapter does not work with VS 2017 yet, so for the Typescript (Jasmine) testing that left me with Chutzpah. No matter what I try I cannot write the simplest of Jasmine tests and have the Visual Studio Test Explorer recognise it (let alone run the test). I haven't even begun to look at the C# Unit Testing yet.
Can anyone else get a Jasmine Unit Test to be recognised and run in the VS Test Explorer from a clean dotnet new angular solution, I would be very grateful for some advise.

Tutorial for Visual Studio Unit Testing Framework?

I would like start to learn Visual Studio Unit Testing Framework on VS 2012 Express for Web.
Mainly for ASP.NET MVC project.
I already buy the hard copy of Art of unit test from amazon.
But it is lack of tutorial aims for VS unit testing framework.
So any resource i can have?
Another question, when i research on this forum,
I found someone said MSTEST is different from VS unit test framework.
Is the VS 2010 Express built-in unit test is subset of VSTS?
Thanks you.
For all practical purposes mstest is the unit testing framework in Visual Studio 2010. It continues to be the primary unit testing framework in 2012 as well. However now we support extensibility and many 3rd party frameworks like xunit/nunit/gtest etc have adapters for our platform.
For ASP.NET the best place to start is to download the MVC3/MVC4 solutions from Microsoft which contain a rich suite of unit tests with them.

Unit Testing. What are the new Techniques/Tools in .NET 4.0?

I'm doing some research on Unit Testing and most of the questions I see on Stack Overflow about NUnit are at least a year old now. Are you using any new tools for Unit Testing that are available via Visual Studio 2010 and .NET 4.0? Please share any new technologies that you are aware of. Thanks!
MSTest is built into Visual Studio 2010 and we've been using it at my companies since VS 2008. It is robust and simple unit testing framework and you don't have to run anything third-party.
Just create a new unit test project and you should be off to the races.
That said, I know a lot of people who use NUnit and are perfectly happy with it.
NUnit is still one of the most popular unit testing frameworks out there. MsTest is also a popular framework because it is included by default with VS. If you want a framework that does its own thing you could look at XUnit. One I have used in the past and enjoyed is MbUnit.
In my opinion I would spend more time into looking into your mocking framework. They differ far more than testing frameworks. Some of the more popular are Moq, NMock, Easy Mock, Rhino Mocks, if you want free. For paid you have TypeMock and Just Mock. My current preference would be Moq because of the more fluent typing.
One of the recent testing-related cool things that came from Microsoft is Pex. Lifted from the project page:
Pex automatically generates test
suites with high code coverage. Right
from the Visual Studio code editor,
Pex finds interesting input-output
values of your methods, which you can
save as a small test suite with high
code coverage. Microsoft Pex is a
Visual Studio add-in for testing .NET
Framework applications.
Definitely worth checking.

C++ unit testing with VS test professional

Does any one know if I can test native code in VS Test 2010?
As of VS2010, native C++ unit testing is not directly supported by Visual Studio. See MSDN, specifically:
You cannot have test projects with unit tests that use unmanaged C++.
You can still do native C++ unit testing with Visual Studio, but it won't be as integrated as other VS features. See this SO answer for a number of native unit testing frameworks and libraries. I have not used any of those, so I cannot give any guidance there.
I would bite the bullet, download Boost and get the test suite compiled. Once you get into it, it's as easy as VS tests.

NUnit & Visual Studio Unit Testing Framework

Is there a way to create unit tests that can be run with the Visual Studio Unit Testing Framework as well as NUnit? I personally prefer the Visual Studio one, but the build server I am using only does NUnit, so I would like to support both if possible.
EDIT: To clarify, I would like to run my own tests using Visual Studio (without add-ons or extensions), but other collegues would like to use NUnit, and the build server needs NUnit. I cannot change anything except the code, so I thought there would be an easy way to satisfy everyone, but its looking to be a bit of a challenge :)
Sounds like you need a Visual Studio test runner. If you install Gallio, it will use VS test runner to run any kind of unit tests(xUnit, nUnit, MBUnit). Also Resharper and CodeRush have their own test runners.
Here is one way to do that using precompiler directives and aliases via the "using" keyword
JustCode has a unit test runner that can run tests written using xUnit, NUnit, MbUnit, or Visual Studio Unit Testing Framework. You can see it in action here
You can write framework agnostic asserts using a library called Should. It also has a very nice fluent syntax which can be used if you like fluent interfaces. I had a blog post related to the same.
http://nileshgule.blogspot.com/2010/11/use-should-assertion-library-to-write.html