下面是POM依赖
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42</artifactId>
<version>2.1.0.28</version>
</dependency>
数据库连接代码包含在以下路径中
src -> main -> utils -> DatabaseConnection.java
import java.sql.Driver;
import java.util.Properties;
import java.sql.*;
public class DatabaseConnection {
Logger logger = LoggerFactory.getLogger(DatabaseConnection.class);
Connection connection = null;
Properties props = new Properties();
public void getDataBaseConnection() {
try {
Class.forName("com.amazon.redshift.jdbc42.Driver");
logger.info("Connecting to database...");
String jdbcUrl = "jdbc:redshift://endpoint:port/dbname";
String dbUsername = "username";
String dbPassword = "password";
jdbcUrl = jdbcUrl + "?AccessKeyID=" + dbUsername + "&SecretAccessKey=" + dbPassword
+ "&DbUser=admin&ssl=true&tcpKeepAlive=true";
props.setProperty("ssl", "true");
props.setProperty("user", dbUsername);
props.setProperty("password", dbPassword);
connection = DriverManager.getConnection(jdbcUrl, props);
if (connection != null) {
logger.info("Connected to the database!");
} else {
logger.info("Failed to make connection!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
并在testng文件的以下路径中调用上面的代码
src->测试->java->测试->名称->sample_test.java
import utils.DatabaseConnection;
public class sample_test extends TestBase {
DatabaseConnection dbconn = new DatabaseConnection();
@Test
public void db_test(){
dbconn.getDataBaseConnection();
}
}
执行上述操作后,出现以下错误
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: org.apache.maven.plugin.MojoFailureException: Exception in provider
at org.apache.maven.plugin.surefire.SurefirePlugin.assertNoException (SurefirePlugin.java:328)
at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary (SurefirePlugin.java:318)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:892)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:755)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: org.apache.maven.surefire.booter.SurefireExecutionException: Exception in provider
at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess (InPluginVMSurefireStarter.java:87)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider (AbstractSurefireMojo.java:1010)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:862)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:755)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: org.testng.TestNGException:
Cannot instantiate class tests.name.sample_test
at org.testng.internal.objects.InstanceCreator.newInstance (InstanceCreator.java:41)
at org.testng.ITestObjectFactory.newInstance (ITestObjectFactory.java:18)
at org.testng.internal.objects.SimpleObjectDispenser.instantiateUsingDefaultConstructor (SimpleObjectDispenser.java:178)
at org.testng.internal.objects.SimpleObjectDispenser.createInstance (SimpleObjectDispenser.java:87)
at org.testng.internal.objects.SimpleObjectDispenser.dispense (SimpleObjectDispenser.java:40)
at org.testng.internal.objects.GuiceBasedObjectDispenser.dispense (GuiceBasedObjectDispenser.java:28)
at org.testng.internal.ClassImpl.getDefaultInstance (ClassImpl.java:106)
at org.testng.internal.ClassImpl.getInstances (ClassImpl.java:136)
at org.testng.TestClass.getInstances (TestClass.java:129)
at org.testng.TestClass.initTestClassesAndInstances (TestClass.java:109)
at org.testng.TestClass.init (TestClass.java:101)
at org.testng.TestClass.<init> (TestClass.java:66)
at org.testng.TestRunner.initMethods (TestRunner.java:465)
at org.testng.TestRunner.init (TestRunner.java:333)
at org.testng.TestRunner.init (TestRunner.java:286)
at org.testng.TestRunner.<init> (TestRunner.java:176)
at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner (SuiteRunner.java:635)
at org.testng.SuiteRunner.init (SuiteRunner.java:221)
at org.testng.SuiteRunner.<init> (SuiteRunner.java:114)
at org.testng.TestNG.createSuiteRunner (TestNG.java:1338)
at org.testng.TestNG.createSuiteRunners (TestNG.java:1314)
at org.testng.TestNG.runSuitesLocally (TestNG.java:1160)
at org.testng.TestNG.runSuites (TestNG.java:1092)
at org.testng.TestNG.run (TestNG.java:1060)
at org.apache.maven.surefire.testng.TestNGExecutor.run (TestNGExecutor.java:132)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass (TestNGDirectoryTestSuite.java:112)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute (TestNGDirectoryTestSuite.java:99)
at org.apache.maven.surefire.testng.TestNGProvider.invoke (TestNGProvider.java:147)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2 (ReflectionUtils.java:202)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke (ProviderFactory.java:155)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider (ProviderFactory.java:81)
at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess (InPluginVMSurefireStarter.java:82)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider (AbstractSurefireMojo.java:1010)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:862)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:755)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: java.lang.reflect.InvocationTargetException
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance (Constructor.java:490)
at org.testng.internal.objects.InstanceCreator.newInstance (InstanceCreator.java:38)
at org.testng.ITestObjectFactory.newInstance (ITestObjectFactory.java:18)
at org.testng.internal.objects.SimpleObjectDispenser.instantiateUsingDefaultConstructor (SimpleObjectDispenser.java:178)
at org.testng.internal.objects.SimpleObjectDispenser.createInstance (SimpleObjectDispenser.java:87)
at org.testng.internal.objects.SimpleObjectDispenser.dispense (SimpleObjectDispenser.java:40)
at org.testng.internal.objects.GuiceBasedObjectDispenser.dispense (GuiceBasedObjectDispenser.java:28)
at org.testng.internal.ClassImpl.getDefaultInstance (ClassImpl.java:106)
at org.testng.internal.ClassImpl.getInstances (ClassImpl.java:136)
at org.testng.TestClass.getInstances (TestClass.java:129)
at org.testng.TestClass.initTestClassesAndInstances (TestClass.java:109)
at org.testng.TestClass.init (TestClass.java:101)
at org.testng.TestClass.<init> (TestClass.java:66)
at org.testng.TestRunner.initMethods (TestRunner.java:465)
at org.testng.TestRunner.init (TestRunner.java:333)
at org.testng.TestRunner.init (TestRunner.java:286)
at org.testng.TestRunner.<init> (TestRunner.java:176)
at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner (SuiteRunner.java:635)
at org.testng.SuiteRunner.init (SuiteRunner.java:221)
at org.testng.SuiteRunner.<init> (SuiteRunner.java:114)
at org.testng.TestNG.createSuiteRunner (TestNG.java:1338)
at org.testng.TestNG.createSuiteRunners (TestNG.java:1314)
at org.testng.TestNG.runSuitesLocally (TestNG.java:1160)
at org.testng.TestNG.runSuites (TestNG.java:1092)
at org.testng.TestNG.run (TestNG.java:1060)
at org.apache.maven.surefire.testng.TestNGExecutor.run (TestNGExecutor.java:132)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass (TestNGDirectoryTestSuite.java:112)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute (TestNGDirectoryTestSuite.java:99)
at org.apache.maven.surefire.testng.TestNGProvider.invoke (TestNGProvider.java:147)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2 (ReflectionUtils.java:202)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke (ProviderFactory.java:155)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider (ProviderFactory.java:81)
at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess (InPluginVMSurefireStarter.java:82)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider (AbstractSurefireMojo.java:1010)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:862)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:755)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException
at tests.name.sample_test.<init> (sample_test.java:30)
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance (Constructor.java:490)
at org.testng.internal.objects.InstanceCreator.newInstance (InstanceCreator.java:38)
at org.testng.ITestObjectFactory.newInstance (ITestObjectFactory.java:18)
at org.testng.internal.objects.SimpleObjectDispenser.instantiateUsingDefaultConstructor (SimpleObjectDispenser.java:178)
at org.testng.internal.objects.SimpleObjectDispenser.createInstance (SimpleObjectDispenser.java:87)
at org.testng.internal.objects.SimpleObjectDispenser.dispense (SimpleObjectDispenser.java:40)
at org.testng.internal.objects.GuiceBasedObjectDispenser.dispense (GuiceBasedObjectDispenser.java:28)
at org.testng.internal.ClassImpl.getDefaultInstance (ClassImpl.java:106)
at org.testng.internal.ClassImpl.getInstances (ClassImpl.java:136)
at org.testng.TestClass.getInstances (TestClass.java:129)
at org.testng.TestClass.initTestClassesAndInstances (TestClass.java:109)
at org.testng.TestClass.init (TestClass.java:101)
at org.testng.TestClass.<init> (TestClass.java:66)
at org.testng.TestRunner.initMethods (TestRunner.java:465)
at org.testng.TestRunner.init (TestRunner.java:333)
at org.testng.TestRunner.init (TestRunner.java:286)
at org.testng.TestRunner.<init> (TestRunner.java:176)
at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner (SuiteRunner.java:635)
at org.testng.SuiteRunner.init (SuiteRunner.java:221)
at org.testng.SuiteRunner.<init> (SuiteRunner.java:114)
at org.testng.TestNG.createSuiteRunner (TestNG.java:1338)
at org.testng.TestNG.createSuiteRunners (TestNG.java:1314)
at org.testng.TestNG.runSuitesLocally (TestNG.java:1160)
at org.testng.TestNG.runSuites (TestNG.java:1092)
at org.testng.TestNG.run (TestNG.java:1060)
at org.apache.maven.surefire.testng.TestNGExecutor.run (TestNGExecutor.java:132)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass (TestNGDirectoryTestSuite.java:112)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute (TestNGDirectoryTestSuite.java:99)
at org.apache.maven.surefire.testng.TestNGProvider.invoke (TestNGProvider.java:147)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2 (ReflectionUtils.java:202)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke (ProviderFactory.java:155)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider (ProviderFactory.java:81)
at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess (InPluginVMSurefireStarter.java:82)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider (AbstractSurefireMojo.java:1010)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:862)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:755)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: java.lang.ClassNotFoundException: java.sql.SQLException
at java.net.URLClassLoader.findClass (URLClassLoader.java:476)
at java.lang.ClassLoader.loadClass (ClassLoader.java:588)
at java.lang.ClassLoader.loadClass (ClassLoader.java:521)
at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass (IsolatedClassLoader.java:97)
at tests.name.sample_test.<init> (sample_test.java:30)
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance (Constructor.java:490)
at org.testng.internal.objects.InstanceCreator.newInstance (InstanceCreator.java:38)
at org.testng.ITestObjectFactory.newInstance (ITestObjectFactory.java:18)
at org.testng.internal.objects.SimpleObjectDispenser.instantiateUsingDefaultConstructor (SimpleObjectDispenser.java:178)
at org.testng.internal.objects.SimpleObjectDispenser.createInstance (SimpleObjectDispenser.java:87)
at org.testng.internal.objects.SimpleObjectDispenser.dispense (SimpleObjectDispenser.java:40)
at org.testng.internal.objects.GuiceBasedObjectDispenser.dispense (GuiceBasedObjectDispenser.java:28)
at org.testng.internal.ClassImpl.getDefaultInstance (ClassImpl.java:106)
at org.testng.internal.ClassImpl.getInstances (ClassImpl.java:136)
at org.testng.TestClass.getInstances (TestClass.java:129)
at org.testng.TestClass.initTestClassesAndInstances (TestClass.java:109)
at org.testng.TestClass.init (TestClass.java:101)
at org.testng.TestClass.<init> (TestClass.java:66)
at org.testng.TestRunner.initMethods (TestRunner.java:465)
at org.testng.TestRunner.init (TestRunner.java:333)
at org.testng.TestRunner.init (TestRunner.java:286)
at org.testng.TestRunner.<init> (TestRunner.java:176)
at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner (SuiteRunner.java:635)
at org.testng.SuiteRunner.init (SuiteRunner.java:221)
at org.testng.SuiteRunner.<init> (SuiteRunner.java:114)
at org.testng.TestNG.createSuiteRunner (TestNG.java:1338)
at org.testng.TestNG.createSuiteRunners (TestNG.java:1314)
at org.testng.TestNG.runSuitesLocally (TestNG.java:1160)
at org.testng.TestNG.runSuites (TestNG.java:1092)
at org.testng.TestNG.run (TestNG.java:1060)
at org.apache.maven.surefire.testng.TestNGExecutor.run (TestNGExecutor.java:132)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass (TestNGDirectoryTestSuite.java:112)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute (TestNGDirectoryTestSuite.java:99)
at org.apache.maven.surefire.testng.TestNGProvider.invoke (TestNGProvider.java:147)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2 (ReflectionUtils.java:202))
注意:如果我使用 main() 方法执行,代码可以正常工作。但是用上面的配置运行就失败了。
它应该与数据库连接
您使用什么版本的 JDK 来运行该程序?