未能为Intellij中的maven项目执行目标org.apache.maven.plugins:maven surefire插件
我今天正在学习MyBatis并尝试创建第一个项目,但我遇到了以下错误。我尝试过许多不同的在线解决方案,但都不起作用。看起来解决方案是添加一个maven surefire插件,但它不起作用。我非常渴望找到问题所在 谁能帮我看看吗?我真的很感激 例外情况未能为Intellij中的maven项目执行目标org.apache.maven.plugins:maven surefire插件,maven,intellij-idea,Maven,Intellij Idea,我今天正在学习MyBatis并尝试创建第一个项目,但我遇到了以下错误。我尝试过许多不同的在线解决方案,但都不起作用。看起来解决方案是添加一个maven surefire插件,但它不起作用。我非常渴望找到问题所在 谁能帮我看看吗?我真的很感激 例外情况 [INFO] ---------------------< org.example:Day01_MyBatis >---------------------- [INFO] Building Day01_MyBatis 1.0.0-sn
[INFO] ---------------------< org.example:Day01_MyBatis >----------------------
[INFO] Building Day01_MyBatis 1.0.0-snapshot
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Day01_MyBatis ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Day01_MyBatis ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Day01_MyBatis ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\780892\IdeaProjects\Day01_MyBatis\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Day01_MyBatis ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\780892\IdeaProjects\Day01_MyBatis\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-cli) @ Day01_MyBatis ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.852 s
[INFO] Finished at: 2020-10-13T19:37:22-06:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-cli) on project Day01_MyBatis: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with -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/MojoFailureException
[INFO]------------------------------------
[信息]建筑日01\u MyBatis 1.0.0-snapshot
[信息]------------------------------------[jar]---------------------------------
[信息]
[信息]---maven资源插件:2.6:resources(默认资源)@Day01\u MyBatis---
[信息]使用“UTF-8”编码复制筛选的资源。
[信息]正在复制3个资源
[信息]
[信息]---maven编译器插件:3.1:compile(默认编译)@Day01\u MyBatis---
[信息]无需编译-所有类都是最新的
[信息]
[信息]---maven资源插件:2.6:testResources(默认testResources)@Day01\u MyBatis---
[信息]使用“UTF-8”编码复制筛选的资源。
[信息]跳过不存在的资源目录C:\Users\780892\IdeaProjects\Day01\u MyBatis\src\test\resources
[信息]
[信息]---maven编译器插件:3.1:testCompile(默认testCompile)@Day01\u MyBatis---
[信息]检测到更改-重新编译模块!
[信息]正在将1个源文件编译为C:\Users\780892\IdeaProjects\Day01\u MyBatis\target\test classes
[信息]
[信息]---maven surefire插件:2.22.2:test(默认cli)@Day01\u MyBatis---
[信息]
[信息]-------------------------------------------------------
[信息]
[信息]-------------------------------------------------------
[信息]
[信息]结果:
[信息]
[信息]测试运行:0,失败:0,错误:0,跳过:0
[信息]
[信息]------------------------------------------------------------------------
[信息]生成失败
[信息]------------------------------------------------------------------------
[信息]总时间:3.852秒
[信息]完成时间:2020-10-13T19:37:22-06:00
[信息]------------------------------------------------------------------------
[错误]未能在项目第01天执行目标org.apache.maven.plugins:maven surefire plugin:2.22.2:test(默认cli)\u MyBatis:未执行任何测试!(设置-DfailIfNoTests=false忽略此错误。)->[帮助1]
[错误]
[错误]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。
[错误]使用-X开关重新运行Maven以启用完整调试日志记录。
[错误]
[错误]有关错误和可能的解决方案的更多信息,请阅读以下文章:
[错误][帮助1]http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
pom.xml
<groupId>org.example</groupId>
<artifactId>Day01_MyBatis</artifactId>
<version>1.0.0-snapshot</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.6</version>
</dependency>
<dependency>
<groupId>mysql</groupId>**strong text**
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
</dependencies>
org.example
第01天
1.0.0-snapshot
罐子
UTF-8
org.apache.maven.plugins
maven surefire插件
真的
2.22.2
log4j
log4j
1.2.12
朱尼特
朱尼特
4.12
org.mybatis
mybatis
3.5.6
mysql**强文本**
mysql连接器java
8.0.20
考试班
public class MyBatisTest {
public static void main(String[] args) throws IOException {
//1. read the configuration file
InputStream is= Resources.getResourceAsStream("SqlMapConfig.xml");
//2. create SqlSessionFactory
SqlSessionFactoryBuilder builder=new SqlSessionFactoryBuilder();
SqlSessionFactory factory=builder.build(is);
//3. use SqlSessionFactory to create an object
SqlSession sqlsession=factory.openSession();
//4. use SqlSession create Dao interface
UserDao dao=sqlsession.getMapper(UserDao.class);
//5. call the method
List<User> users=dao.findAll();
for(User user:users)
{
System.out.println(user);
}
//6. release resource
sqlsession.close();
is.close();
}
}
公共类MyBatisTest{
公共静态void main(字符串[]args)引发IOException{
//1.读取配置文件
InputStream is=Resources.getResourceAsStream(“SqlMapConfig.xml”);
//2.创建SqlSessionFactory
SqlSessionFactoryBuilder=新SqlSessionFactoryBuilder();
SqlSessionFactory=builder.build(is);
//3.使用SqlSessionFactory创建对象
SqlSession SqlSession=factory.openSession();
//4.使用SqlSession创建Dao接口
UserDao=sqlsession.getMapper(UserDao.class);
//5.调用该方法
List users=dao.findAll();
for(用户:用户)
{
System.out.println(用户);
}
//6.释放资源
sqlsession.close();
is.close();
}
}
您的测试类实际上不是java单元测试意义上的测试类,而是一个主类。
你想要什么
然后用具有junit@test注释的测试方法替换主方法。 另见此处:
然后从pom.xml中删除junit依赖项和surefire插件