protected override void OnCreate()
        {
            base.OnCreate();

            NUnitLogs.LogMessage($"***********OnCreateMobile***********");

            // Tizen will not load all tests within the current project,
            // you must do it explicitly below
            var nunit = new NUnit.Runner.App();

            // If you want to add tests in another assembly, add a reference and
            // duplicate the following line with a type from the referenced assembly
            //nunit.AddTestAssembly(typeof(MainPage).GetTypeInfo().Assembly);
            //nunit.AddTestAssembly(typeof(Program).GetTypeInfo().Assembly);
            nunit.AddTestAssembly(typeof(TestClass1).GetTypeInfo().Assembly);

            // Available options for testing
            nunit.Options = new TestOptions
            {
                // If True, the tests will run automatically when the app starts
                // otherwise you must run them manually.
                AutoRun = true,

                // If True, the application will terminate automatically after running the tests.
                //TerminateAfterExecution = true,

                // Information about the tcp listener host and port.
                // For now, send result as XML to the listening server.
                // NOTE: Your UWP App must have Private Networks capability enabled
                //TcpWriterParameters = new TcpWriterInfo("192.168.0.108", 13000),

                // Creates a NUnit Xml result file on the host file system using PCLStorage library.
                CreateXmlResultFile = true,

                // Choose a different path for the xml result file
                // ResultFilePath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.TemporaryFolder.Path, "Nunit", "Results.xml")
                //ResultFilePath = Application.Current.DirectoryInfo.Data + "Results.xml"
            };

            LoadApplication(nunit);
        }
Example #2
0
        public async Task BeforeAllAsync()
        {
            await Profiler.Run(
                async() =>
            {
                // Set up logging
                LogEventLevel consoleLevel = Context.Current.Verbose
                        ? LogEventLevel.Verbose
                        : LogEventLevel.Information;
                var loggerConfig = new LoggerConfiguration()
                                   .MinimumLevel.Verbose()
                                   .WriteTo.NUnit(consoleLevel);
                Context.Current.LogFile.ForEach(f => loggerConfig.WriteTo.File(f));
                Log.Logger = loggerConfig.CreateLogger();

                // Install IoT Edge
                using (var cts = new CancellationTokenSource(Context.Current.SetupTimeout))
                {
                    // NUnit's [Timeout] attribute isn't supported in .NET Standard
                    // and even if it were, it doesn't run the teardown method when
                    // a test times out. We need teardown to run, to remove the
                    // device registration from IoT Hub and stop the daemon. So
                    // we have our own timeout mechanism.
                    DateTime startTime      = DateTime.Now;
                    CancellationToken token = cts.Token;

                    Assert.IsNull(this.device);
                    this.device = await EdgeDevice.GetOrCreateIdentityAsync(
                        Context.Current.DeviceId,
                        this.iotHub,
                        token);

                    await this.daemon.UninstallAsync(token);
                    await this.daemon.InstallAsync(
                        this.device.ConnectionString,
                        Context.Current.PackagePath,
                        Context.Current.Proxy,
                        token);

                    try
                    {
                        await this.daemon.WaitForStatusAsync(EdgeDaemonStatus.Running, token);

                        var agent = new EdgeAgent(this.device.Id, this.iotHub);
                        await agent.WaitForStatusAsync(EdgeModuleStatus.Running, token);
                        await agent.PingAsync(token);
                    }

                    // ReSharper disable once RedundantCatchClause
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        await NUnitLogs.CollectAsync(startTime, token);
                    }
                }
            },
                "Completed end-to-end test setup");
        }