2

I have an issue here, as soon as I hit compile , mstest cmd prompt shows up then it crashes/goes away and my test won't get executed. This is the code :

 public void test(String testContainer, String testName)
    {

       // String Path = @"C:\Program Files\Microsoft Visual Studio 10.0 Common7\IDE\mstest.exe";
          String Path = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe";
       // String Path = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat""";



         Process myProcess = new Process();
       // ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, "/testsettings:local.testsettings /testcontainer:" + testContainer + " /test:" + testName);
       ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, "MSTest/testcontainer:" + testContainer + " /test:" + testName + @"/testcategory:""ActionCol""");

       myProcessStartInfo.UseShellExecute = false; 
       myProcess.StartInfo = myProcessStartInfo;

       myProcess.Start();
      // MessageBox.Show(x + "\n" + y);
    }

And this is how I call this method :

private void button3_Click(object sender, EventArgs e)
        {
            x = @"C:\Users\butoiu.edward\Desktop\Lucru\SimarpiUnitTest\GestcollTestSolution\CodedUITestProject\bin\Debug\GestcollTestProject.dll";
            y = "ActionCollInsert";
            test(x, y);
        }

What am I doing wrong ? Really need some help here, thanks in advance

EDIT 1 - this is how a testmethod looks like in my other project., forgot to mention I have 2 projects under the same solution ( doesn't change a thing, but I think it's worth mentioning)

[TestMethod(), TestCategory("ActionCol")]
        public void ActionCollInsert()
        {
            MessageBox.Show("test");

            //using the proper map
            var actionColTest = new ActionColMap();
            //actionColTest.ActionColOpen1();

            // actionColTest.ActionColSlider();
            actionColTest.ActionColHideCollumns();

            actionColTest.ActionColInsert();

            actionColTest.ActionColInsertCode();
            actionColTest.ActionColInsertDesc();
            actionColTest.ActionColSave();

        }

EDIT2 - How I start DEV-CMD - using shell to start my cmd from it's shortcut's position fixed up things for me.As I fixed this issue, a new one appeared. I can't pass arguments into the cmd, I mean nothing happens.

public void test(String testContainer, String testName)
        {

           //   String Path = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe";
            String Path = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Visual Studio 2012\Visual Studio Tools\Developer Command Prompt for VS2012.lnk"; 

             Process myProcess = new Process();
           // ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, "/testsettings:local.testsettings /testcontainer:" + testContainer + " /test:" + testName);
           ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, "MSTest/testcontainer:" + testContainer + " /test:" + testName );

            myProcessStartInfo.UseShellExecute = true;
            myProcessStartInfo.Arguments = "blah blah"; // - this ain't working !!!!
            myProcess.StartInfo = myProcessStartInfo;

           myProcess.Start();

        }

EDIT3 - I am able to start a cmd and pass some arguments to it ( source : Passing an argument to cmd.exe). But changing the path to my dev cmd prompt will not insert automatically the parameter. Need some help, /c has no effect on dev cmd.

            ProcessStartInfo proc = new ProcessStartInfo();
            proc.FileName = Path;
            proc.Arguments = @"/c ping 10.2.2.125";
            proc.UseShellExecute = true;
            Process.Start(proc);
Community
  • 1
  • 1
ExtremeSwat
  • 794
  • 1
  • 12
  • 34
  • are you shure it crashes? are there any exceptions? can you show the part where the actual test is declared (with Category etc..). Maybe its a problem that there are no whitespaces between the cmd-line-args? – nozzleman Aug 13 '14 at 09:07
  • There are no exceptions, I've tried try-catching the whole method to see if it throws something. No errors whatsoever, also running mstest.exe from the directory directly by me will have the same behaviour. The app starts, I can see the window, then it disappears in less than a second, behaving like a bat, please check my post, I've edited it ( I think I wrote crash earlier, sorry ) – ExtremeSwat Aug 13 '14 at 10:25
  • I made a form with a button that executes this action, pressing that button x times will cause the appear-disappear of mstest.exe x times, my project isn't crashing or throwing any kind of error. – ExtremeSwat Aug 13 '14 at 10:27
  • Can you execute the command by hand using cmd? – nozzleman Aug 13 '14 at 10:37
  • I can manually execute it by doing this: - starting Developer Command Prompt for VS2012 ( if I manually execute MSTest.exe it will have the same behavior when I execute it through my app) - writing MSTest/testcontainer: fullURL /testcategory: whatever.So yeah it works manually by using dev cmd but not mstest. I've tried running Dev cmd for VS2012 from my C# app but I get an error ( file not found ), check out my code, that's how the actual url of it looks like (the .bat exec) – ExtremeSwat Aug 13 '14 at 10:41
  • From what it looks like, I need to execute DEV CMD for VS2012, but I fail to do so due it's weird targeting – ExtremeSwat Aug 13 '14 at 10:45
  • 1
    as dumb as it may sound, i guess you have to call it over explicit call to cmd.exe like ´Process.Start("cmd.exe /C \"c:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat\"")´ and so on. Unfortunately, this is my only idea :( – nozzleman Aug 13 '14 at 10:56
  • third edit, I only need to find out how to pass arguments to this dev cmd and I'm done. – ExtremeSwat Aug 13 '14 at 11:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/59267/discussion-between-nozzleman-and-extremeswat). – nozzleman Aug 13 '14 at 11:26

1 Answers1

1

You can try creating Batch script which can build environment for mstest and trigger the test accordingly

please find below example. you just need to replace correct path for vcvarsall.bat for your system

cd\
cd "Program Files <x86>"\"Microsoft Visual Studio 12.0"\VC
call "vcvarsall.bat"
cd\
C:
Mstest /testcontainer:Test.dll /resultsfile:result.trx
Kuldeep Vasani
  • 310
  • 1
  • 3
  • 13