static void Run() // HTML body.onload event entry point, see index.html { var assembly = typeof(TestRunner).Assembly; foreach (var type in assembly.GetTypes()) { if (type.GetCustomAttributes(typeof(TestAttribute), false).Count > 0) { Console.WriteLine(type.FullName); var methods = type.GetMethods(); var setup = methods.SingleOrDefault(m => m.GetCustomAttributes(typeof(TestSetup), false).Any()); var tests = methods.Where(m => m.GetCustomAttributes(typeof(TestMethodAttribute), false).Any()); foreach (var test in tests) { QUnit.test(type.FullName + "." + test.Name, () => { var instance = type.GetConstructors()[0].Invoke(new object[0]); if (setup != null) { setup.Invoke(instance, new object[0]); } test.Invoke(instance, new object[0]); }); } } } }
public static void DefineScript() { sap.ui.define(new string[] { "manu/toolpageapp/fv/model/formatter", "sap/ui/thirdparty/sinon", "sap/ui/thirdparty/sinon-qunit" }, new Action <Formatter>( (formatter) => { var testObj = new TestFormatter(); testObj.formatter = formatter; QUnit.module("homeImages", new Hooks() { beforeEach = (Assert assert) => { testObj.formatter = formatter; } }); QUnit.test("Should display the reduced image on small screen sizes", (Assert assert) => { testObj.imageSourceTestCase(assert, true, "/images/homeImage_small.jpg"); }); QUnit.test("Should display the original image on large screen sizes", (Assert assert) => { testObj.imageSourceTestCase(assert, false, "/images/homeImage.jpg"); }); } ) ); }
public static void Script() { sap.ui.require(new string[] { "sap/ui/demo/walkthrough/model/formatter", "sap/ui/model/resource/ResourceModel", "sap/ui/thirdparty/sinon", "sap/ui/thirdparty/sinon-qunit" }, new Action <Formatter>( (formatter) => { sap.ui.model.resource.ResourceModel oResourceModel = null; QUnit.module("Test Module", new Hooks() { beforeEach = (Assert assert) => { oResourceModel = new sap.ui.model.resource.ResourceModel(new sap.ui.model.resource.ResourceModel.ResourceModelInfo() { bundleUrl = jQuery.sap.getModulePath("sap.ui.demo.walkthrough", "/i18n/i18n.properties") }); }, afterEach = (Assert assert) => { oResourceModel.destroy(); } }); QUnit.test("Should return the translated texts", (Assert assert) => { // Arrange var oModel = This.Instance.As <FormatterTests>().stub(); oModel.withArgs("i18n").As <SinonStub>().returns(oResourceModel); var oViewStub = new { getModel = oModel }; var oControllerStub = new { getView = This.Instance.As <FormatterTests>().stub().returns(oViewStub) }; // System under test var fnIsolatedFormatter = Globals.BindMethod <Func <string, string> >(formatter, nameof(formatter.statusText), oControllerStub); assert.strictEqual(fnIsolatedFormatter("A"), "New", "The long text for status A is correct"); assert.strictEqual(fnIsolatedFormatter("B"), "In Progress", "The long text for status B is correct"); assert.strictEqual(fnIsolatedFormatter("C"), "Done", "The long text for status C is correct"); assert.strictEqual(fnIsolatedFormatter("Foo"), "Foo", "The long text for status Foo is correct"); } ); } ) ); }
public static void DefineScript() { sap.ui.define(new string[] { "manu/toolpageapp/fv/model/models", "sap/ui/thirdparty/sinon", "sap/ui/thirdparty/sinon-qunit" }, new Action <Models>( (models) => { var testObj = new TestModels(); testObj.models = models; QUnit.module("createDeviceModel", new Hooks() { afterEach = (Assert assert) => { testObj.oDeviceModel.destroy(); } }); QUnit.test("Should initialize a device model for desktop", (Assert assert) => { testObj.isPhoneTestCase(assert, false); }); QUnit.test("Should initialize a device model for phone", (Assert assert) => { testObj.isPhoneTestCase(assert, true); }); QUnit.test("Should initialize a device model for non touch devices", (Assert assert) => { testObj.isTouchTestCase(assert, false); }); QUnit.test("Should initialize a device model for touch devices", (Assert assert) => { testObj.isTouchTestCase(assert, true); }); QUnit.test("The binding mode of the device model should be one way", (Assert assert) => { // System under test testObj.oDeviceModel = new Models().createDeviceModel(); // Assert assert.strictEqual(testObj.oDeviceModel.getDefaultBindingMode(), sap.ui.model.BindingMode.OneWay, "Binding mode is correct"); }); } ) ); }