Results 1 to 5 of 5

Thread: "No static 'Main' method" error when running Unit Test project

  1. #1
    Tpiom is offline C# Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Mar 2017
    Posts
    3
    Rep Power
    0

    "No static 'Main' method" error when running Unit Test project

    I'm trying to setup a test framework in Sharpdevelop (open source and leightweight alt. to Visual Studio), but there's this guide where the creator is using Visual Studio.

    He first creates a new project, called WordpressAutomation and a Class Library with the following code in it:
    Code:
    Using system;
    using system.collections.generic;
    using system.linq;
    using system.text;
    using system.threading.tasks;
    using openqa.selenium.firefox; // used to control browser
    
    namespace WordpressAutomation
    {
        public class Class1
     {
            public void Go()
        {
        var driver = new FirefoxDriver();
        driver.Navigate().GoToUrl("http://www.google.com");
        }
      }
    }
    He then creates another project, using the Unit test Project template in the solution and calls WordpressTests. It has the following code in it.

    Code:
    using system;
    using microsoft.visualstudio.testtools.unittesting;
    using wordpressautomation;
    
    namespace WordpressTests
    {
                                 [TestClass]
                                 public class UnitTest1
                                 {
                                                              [TestMethod]
                                                              public void TestMethod()
                                                              {
                                                                                           var c = new Class1();
                                                                                           c.Go();
                                                              }
                                 }
    }
    He basically references the wordpressautomation code in his wordpresstest project... it opens up Firefox. Easy.

    Now Sharpdevelop doesn't have a "unit test" project template so I created an empty project instead, then a Unit Test class and went from there.
    However, when trying to run it gives me the "CS5001 - does not contain a static 'Main' method suitable for an entry point" error.

    How can I fix this?
    Thanks!

  2. #2
    JohnH's Avatar
    JohnH is offline C# Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Location
    Norway
    Posts
    331
    Rep Power
    87
    A Unit Test Project in VS is a class library application type, if that helps.

  3. #3
    Tpiom is offline C# Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Mar 2017
    Posts
    3
    Rep Power
    0
    I changed output type to "Class Library" and it now tries to run, I think, but gives me another error:
    "Can not start process. is not a valid Win32 application (Exception from HRESuLT 0x800700C1)

  4. #4
    JohnH's Avatar
    JohnH is offline C# Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Location
    Norway
    Posts
    331
    Rep Power
    87
    Depends on what you mean by "run", in VS one use a Test menu to run tests, and not "run" as regular executable project. I think it is similar in Sharpdevelop - check out web.

  5. #5
    Tpiom is offline C# Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Mar 2017
    Posts
    3
    Rep Power
    0
    Ah, of course... Thanks for the help people!

    Now it says: "OpenQA.Selenium.WebDriverException : Cannot find Firefox binary in PATH or default install locations. Make sure Firefox is installed. OS appears to be: Vista" but I think it's because the driver isn't up-to-date, based on information gathered from here: https://www.ultimateqa.com/common-se...er-errors-fix/

    Also, for some reason I had to place the driver .exe in my project folder (C:\Users\XXXXX\Documents\SharpDevelop Projects\WordpressAutomation\WordpressAutomation\b in\Debug) or it wouldn't find it.

    But now it runs as it should.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •