What is it?TSTestAdapter is a simple extension that searches for .test.ts files and identify test methods. Using PhantomJS it runs the scripts. Source Code available on Github Requirements
Optional
How to use?Make sure your test file is named correctly as .test.ts All your test methods must be in a class. You need to "register" the methods to be tested.
tl;dr; create a class with methods, if test didn't pass throw exception. And see how to register methods bellow
Creating a test classIn this example I am referencing `UnitTest.ts` which is a custom library I created. You canuse any test framework you want, the only required thing is that it must throw an exception with the error message.
JavaScript Edit|Remove js/// <reference path="UnitTest.ts" />class YourClassName{ private valueInput: number[] = [3, 100, 1, 2]; Aggregate(): void { var expected = 106; var result = 106; Assert.AreEqual(expected, result, "values must be equal"); } Select(): void { Assert.AreEqual(0, 1, "values must be equal"); } Where(): void { Assert.AreEqual(0, 0); } NonTestable(): void { }} /// <reference path="UnitTest.ts" /> class YourClassName { private valueInput: number[] = [3, 100, 1, 2]; Aggregate(): void { var expected = 106; var result = 106; Assert.AreEqual(expected, result, "values must be equal"); } Select(): void { Assert.AreEqual(0, 1, "values must be equal"); } Where(): void { Assert.AreEqual(0, 0); } NonTestable(): void { } } Assert.AreEqual implementation throws an error if the values are not equal, this isrequired to happen for the extension to know the test didn't pass. JavaScript Edit|Remove jsclass Assert{ public static AreEqual<T>(expected: T, actual: T, message: string = null): void { if (expected != actual) { throw "Assert.AreEqual failed. " + "Expected: <" + expected + ">. " + "Actual: <" + actual + ">. " + message; } }} class Assert { public static AreEqual<T>(expected: T, actual: T, message: string = null): void { if (expected != actual) { throw "Assert.AreEqual failed. " + "Expected: <" + expected + ">. " + "Actual: <" + actual + ">. " + message; } } } Registering the testable methodsAnd the last required thing it to tell the extension which methods are testable, at least for now this is the way to do it. (if TestBase is already in use by your code, you can wrap it in a closure). The extension will split at `.prototype.`, then to test it will create an instance of the class and then call the method. If you have test startup requirements you can do it on the class constructor (parameterless). JavaScript Edit|Remove jsvar TestBase = { RegisterTestMethod: function (a, b, c) { }};TestBase.RegisterTestMethod(YourClassName.prototype.Aggregate, "Aggregate test", "Runs aggregation and stuff");TestBase.RegisterTestMethod(YourClassName.prototype.Select, "Select test", "Runs selection and stuff");TestBase.RegisterTestMethod(YourClassName.prototype.Where, "Where test", "Runs where and stuff"); var TestBase = { RegisterTestMethod: function (a, b, c) { } }; TestBase.RegisterTestMethod(YourClassName.prototype.Aggregate, "Aggregate test", "Runs aggregation and stuff"); TestBase.RegisterTestMethod(YourClassName.prototype.Select, "Select test", "Runs selection and stuff"); TestBase.RegisterTestMethod(YourClassName.prototype.Where, "Where test", "Runs where and stuff");
Screenshots- |