发表于: 2017-07-14 23:45:18
1 1088
今天完成的事情:
23.将部署自己服务到服务器上,包括Maven,Mysql客户端等。直接用Maven命令跑单元测试。
自己单独使用Junit的时候可以顺利运行,但是使用maven的test的话Resources读不出来,得把文件移出来,在百度上查不到答案
项目结构
运行maven的test
---------------------------------test结果分割线-------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MybatisTest 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MybatisTest ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MybatisTest ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 3 source files to G:\IdeaProjects\MybatisTest\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MybatisTest ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory G:\IdeaProjects\MybatisTest\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MybatisTest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MybatisTest ---
[INFO] Surefire report directory: G:\IdeaProjects\MybatisTest\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running UserCRUDTest
Success
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.017 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.092 s
[INFO] Finished at: 2017-07-14T21:01:09+08:00
[INFO] Final Memory: 16M/168M
[INFO] ------------------------------------------------------------------------
---------------------------------test结果分割线-------------------------------------------
24.直接执行Main方法,去在服务器上跑通流程。
写日报的时候才发现审题错误,也罢,将错就错,运行main方法放在明天吧
使用maven、tomcat将war项目部署到服务器的流程
pom.xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>WebTest</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<url>http://39.108.78.2:8080/manager/text</url>
<server>tomcatserver</server>
<path>/mycontext</path>
<username>yourusername</username>
<password>yourpassword</password>
</configuration>
</plugin>
</plugins>
</build>
</project>
index.jsp
简单的hello world
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
maven命令:
clean(清除生成的文件)
install(生成包到本地仓库)
tomcat -deploy
测试结果:
---------------------------------test结果分割线-------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building WebTest Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> tomcat-maven-plugin:1.1:redeploy (default-cli) > package @ WebTest >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ WebTest ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ WebTest ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ WebTest ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory G:\IdeaProjects\WebTest\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ WebTest ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ WebTest ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ WebTest ---
[INFO] Packaging webapp
[INFO] Assembling webapp [WebTest] in [G:\IdeaProjects\WebTest\target\WebTest]
[INFO] Processing war project
[INFO] Copying webapp resources [G:\IdeaProjects\WebTest\src\main\webapp]
[INFO] Webapp assembled in [25 msecs]
[INFO] Building war: G:\IdeaProjects\WebTest\target\WebTest.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] <<< tomcat-maven-plugin:1.1:redeploy (default-cli) < package @ WebTest <<<
[INFO]
[INFO]
[INFO] --- tomcat-maven-plugin:1.1:redeploy (default-cli) @ WebTest ---
[INFO] Deploying war to http://39.108.78.2:8080/mycontext
[INFO] OK - Deployed application at context path [/mycontext]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.739 s
[INFO] Finished at: 2017-07-15T00:05:22+08:00
[INFO] Final Memory: 11M/161M
[INFO] ------------------------------------------------------------------------
---------------------------------test结果分割线-------------------------------------------
明天计划的事情:
1. 把jar包放到服务器上使用main跑通流程
2. 把下面的数据库任务做一下
3. 看看其他师兄是怎么做任务1总结的,去看下SVN和Github教程,还有深度思考尽快把任务1做完
遇到的问题:
1. maven的测试功能不能读取resources文件夹中的文件,但自己单个点击测试用例却可以,没查到相关的答案。妥协方案是把resources中的文件放到java文件夹下
2. jar包不能使用tomcat -deploy功能部署到服务器,明天直接用工具复制粘贴过去吧
收获:
学会了怎么用maven集成测试用例,以及如何把web项目部署到服务器上的方法
评论