title: Getting 'SurefireExecutionException' while running TestNG project via maven test
body: <p>I have a main class that I want to run via maven, this main class dynamically creates testng.xml file and that's how the testing starts. But when I run my project via 'Run as->maven test' I get 'SurefireExecutionException' . Below is the pom.xml:</p>
  
  <pre><code>&lt;build&gt;
      &lt;pluginManagement&gt;
        &lt;plugins&gt;
          &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.22.1&lt;/version&gt;
            &lt;configuration&gt;
            &lt;forkMode&gt;never&lt;/forkMode&gt;
            &lt;parallel&gt;tests&lt;/parallel&gt;
            &lt;threadCount&gt;10&lt;/threadCount&gt;
            &lt;/configuration&gt;
          &lt;/plugin&gt;
           &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.8.0&lt;/version&gt;
          &lt;configuration&gt;
            &lt;source&gt;1.8&lt;/source&gt;
            &lt;target&gt;1.8&lt;/target&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
    &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
    &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;1.2.1&lt;/version&gt;
    &lt;executions&gt;
      &lt;execution&gt;
        &lt;goals&gt;
          &lt;goal&gt;java&lt;/goal&gt;
        &lt;/goals&gt;
      &lt;/execution&gt;
    &lt;/executions&gt;
    &lt;configuration&gt;
      &lt;mainClass&gt;main.MainRunner&lt;/mainClass&gt;
      &lt;arguments&gt;
      &lt;/arguments&gt;
    &lt;/configuration&gt;
  &lt;/plugin&gt;
        &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
    &lt;/build&gt;
  
  
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;3.8.1&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
      &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
      &lt;version&gt;3.14.0&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
      &lt;artifactId&gt;poi&lt;/artifactId&gt;
      &lt;version&gt;4.0.0&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.relevantcodes&lt;/groupId&gt;
      &lt;artifactId&gt;extentreports&lt;/artifactId&gt;
      &lt;version&gt;2.41.2&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
      &lt;artifactId&gt;poi-ooxml-schemas&lt;/artifactId&gt;
      &lt;version&gt;4.0.0&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
      &lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
      &lt;version&gt;4.0.0&lt;/version&gt;
  &lt;/dependency&gt;
     &lt;dependency&gt;
      &lt;groupId&gt;commons-io&lt;/groupId&gt;
      &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
      &lt;version&gt;2.6&lt;/version&gt;
  &lt;/dependency&gt;
  
    &lt;/dependencies&gt;
  </code></pre>
  
  <p>and this is the stacktrace:</p>
  
  <pre><code>[INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 2.683 s
  [INFO] Finished at: 2018-12-20T19:07:20+05:30
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project Automata: There are test failures.
  [ERROR] 
  [ERROR] Please refer to D:\Git\automata\Automata\target\surefire-reports for the individual test results.
  [ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
  [ERROR] Exception in provider
  [ERROR] org.apache.maven.surefire.booter.SurefireExecutionException: Exception in provider
  [ERROR]     at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess(InPluginVMSurefireStarter.java:91)
  [ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1166)
  [ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1011)
  [ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:857)
  [ERROR]     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
  [ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
  [ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
  [ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
  [ERROR]     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
  [ERROR]     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
  [ERROR]     at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
  [ERROR]     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
  [ERROR]     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
  [ERROR]     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
  [ERROR]     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
  [ERROR]     at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
  [ERROR]     at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
  [ERROR]     at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
  [ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  [ERROR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  [ERROR]     at java.lang.reflect.Method.invoke(Unknown Source)
  [ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
  [ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
  [ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
  [ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
  [ERROR] Caused by: java.lang.NoClassDefFoundError: org/testng/ITestContext
  [ERROR]     at java.lang.Class.getDeclaredMethods0(Native Method)
  [ERROR]     at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
  [ERROR]     at java.lang.Class.privateGetMethodRecursive(Unknown Source)
  [ERROR]     at java.lang.Class.getMethod0(Unknown Source)
  [ERROR]     at java.lang.Class.getMethod(Unknown Source)
  [ERROR]     at org.apache.maven.surefire.util.ReflectionUtils.tryGetMethod(ReflectionUtils.java:60)
  [ERROR]     at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isSuiteOnly(JUnit3TestChecker.java:66)
  [ERROR]     at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isValidJUnit3Test(JUnit3TestChecker.java:61)
  [ERROR]     at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.accept(JUnit3TestChecker.java:56)
  [ERROR]     at org.apache.maven.surefire.junit.PojoAndJUnit3Checker.accept(PojoAndJUnit3Checker.java:44)
  [ERROR]     at org.apache.maven.surefire.util.DefaultScanResult.applyFilter(DefaultScanResult.java:102)
  [ERROR]     at org.apache.maven.surefire.junit.JUnit3Provider.scanClassPath(JUnit3Provider.java:147)
  [ERROR]     at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:91)
  [ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  [ERROR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  [ERROR]     at java.lang.reflect.Method.invoke(Unknown Source)
  [ERROR]     at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:206)
  [ERROR]     at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:161)
  [ERROR]     at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:84)
  [ERROR]     at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess(InPluginVMSurefireStarter.java:87)
  [ERROR]     ... 25 more
  [ERROR] Caused by: java.lang.ClassNotFoundException: org.testng.ITestContext
  [ERROR]     at java.net.URLClassLoader.findClass(Unknown Source)
  [ERROR]     at java.lang.ClassLoader.loadClass(Unknown Source)
  [ERROR]     at java.lang.ClassLoader.loadClass(Unknown Source)
  [ERROR]     at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:100)
  [ERROR]     ... 46 more
  [ERROR] -&gt; [Help 1]
  [ERROR] 
  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  [ERROR] 
  [ERROR] For more information about the errors and possible solutions, please read the following articles:
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  </code></pre>
  
  <p>Edit: Like suggested by Krishnan below, I added the testng dependency in my pom.xml file, after doing that it looks like BeforeSuite and BeforeTest classes are working, but the actual tests aren't working, this is what I get now:</p>
  
  <pre><code>Surefire suite started.....
  In Before Test
  Starting ChromeDriver 2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90) on port 25689
  Only local connections are allowed.
  [1545327410.041][WARNING]: Timed out connecting to Chrome, retrying...
  Dec 20, 2018 11:06:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
  INFO: Detected dialect: OSS
  new instance
  Surefire suite ended.....
  [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 31.895 s - in TestSuite
  [INFO] 
  [INFO] Results:
  [INFO] 
  [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
  [INFO] 
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD SUCCESS
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 35.638 s
  [INFO] Finished at: 2018-12-20T23:06:58+05:30
  [INFO] ------------------------------------------------------------------------
  </code></pre>
  
  <p>I would really appreciate if some light is thrown on this.</p>
  
  <p>Edit: Opened up a new question for the above query here: 
  <a href="https://stackoverflow.com/questions/53874321/unable-to-run-testng-tests-from-maven">Unable to run testNG tests from maven</a></p>