Beispiel #1
0
        private void EndTesting(bool failure)
        {
            Logger.Debug(@"Execute tests done");

            // Read result file
            var result = File.Exists(resultFile) ? File.ReadAllText(resultFile) : "";

            // Delete result file
            if (File.Exists(resultFile))
            {
                File.Delete(resultFile);
            }

            // Display some useful info
            var output = stringBuilder.ToString();

            Console.WriteLine(output);

            Logger.Debug(@"Sending results to server");

            // Send back result
            var binaryWriter = new BinaryWriter(socketContext.WriteStream);

            binaryWriter.Write(failure);
            binaryWriter.Write(output);
            binaryWriter.Write(result);

            Logger.Debug(@"Close connection");

            ImageTester.Disconnect();

            socketContext.WriteStream.Flush();

            socketContext.Dispose();

            Finish();
        }
        protected override void OnDestroy()
        {
            ImageTester.Disconnect();

            base.OnDestroy();
        }
        private void RunTests()
        {
            var serverAddresses = Intent.GetStringExtra(TestRunner.ParadoxServerIp);
            var serverPort      = Int32.Parse(Intent.GetStringExtra(TestRunner.ParadoxServerPort) ?? "8080");
            var buildNumber     = Int32.Parse(Intent.GetStringExtra(TestRunner.ParadoxBuildNumber) ?? "-1");
            var branchName      = Intent.GetStringExtra(TestRunner.ParadoxBranchName) ?? "";

            // Remove extra (if activity is recreated)
            Intent.RemoveExtra(TestRunner.ParadoxServerIp);
            Intent.RemoveExtra(TestRunner.ParadoxServerPort);
            Intent.RemoveExtra(TestRunner.ParadoxBuildNumber);
            Intent.RemoveExtra(TestRunner.ParadoxBranchName);


            Logger.Info(@"*******************************************************************************************************************************");
            Logger.Info(@"date: " + DateTime.Now);
            Logger.Info(@"server addresses: " + serverAddresses);
            Logger.Info(@"port: " + serverPort);
            Logger.Info(@"*******************************************************************************************************************************");

            // Connect to server right away to let it know we're alive
            var client = Connect(serverAddresses, serverPort);

            // Update build number (if available)
            ImageTester.ImageTestResultConnection.BuildNumber = buildNumber;
            ImageTester.ImageTestResultConnection.BranchName  = branchName ?? "";

            // Connect beforehand to image tester, so that first test timing is not affected by initial connection
            try
            {
                ImageTester.Connect();
            }
            catch (Exception e)
            {
                Logger.Error("Error connecting to image tester server: {0}", e);
            }

            // Start unit test
            var cachePath = CacheDir.AbsolutePath;
            var timeNow   = DateTime.Now;

            // Generate result file name
            var resultFile = Path.Combine(cachePath, string.Format("TestResult-{0:yyyy-MM-dd_hh-mm-ss-tt}.xml", timeNow));

            Logger.Debug(@"Execute tests");

            var stringBuilder = new StringBuilder();
            var stringWriter  = new StringWriter(stringBuilder);

            new TextUI(stringWriter).Execute(new [] { "-format:nunit2", string.Format("-result:{0}", resultFile) });

            Logger.Debug(@"Execute tests done");

            // Read result file
            var result = File.ReadAllText(resultFile);

            // Delete result file
            File.Delete(resultFile);

            // Display some useful info
            var output = stringBuilder.ToString();

            Console.WriteLine(output);

            Logger.Debug(@"Sending results to server");

            // Send back result
            var binaryWriter = new BinaryWriter(client.GetStream());

            binaryWriter.Write(output);
            binaryWriter.Write(result);

            Logger.Debug(@"Close connection");

            ImageTester.Disconnect();

            client.Close();

            Finish();
        }