Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
老丢丢
SpringBoot2Demo
提交
d933ea83
S
SpringBoot2Demo
项目概览
老丢丢
/
SpringBoot2Demo
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBoot2Demo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d933ea83
编写于
11月 10, 2020
作者:
Q
qinxiaodong@pannk.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新
上级
213cc407
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
260 addition
and
0 deletion
+260
-0
pom.xml
pom.xml
+1
-0
testing/pom.xml
testing/pom.xml
+30
-0
testing/src/main/java/com/pannk/demo/App.java
testing/src/main/java/com/pannk/demo/App.java
+14
-0
testing/src/main/java/com/pannk/demo/controller/HelloController.java
.../main/java/com/pannk/demo/controller/HelloController.java
+21
-0
testing/src/main/java/com/pannk/demo/service/CallService.java
...ing/src/main/java/com/pannk/demo/service/CallService.java
+12
-0
testing/src/main/java/com/pannk/demo/service/HelloService.java
...ng/src/main/java/com/pannk/demo/service/HelloService.java
+12
-0
testing/src/main/java/com/pannk/demo/service/impl/CallServiceImpl.java
...ain/java/com/pannk/demo/service/impl/CallServiceImpl.java
+23
-0
testing/src/main/java/com/pannk/demo/service/impl/HelloServiceImpl.java
...in/java/com/pannk/demo/service/impl/HelloServiceImpl.java
+16
-0
testing/src/main/resources/application.yml
testing/src/main/resources/application.yml
+0
-0
testing/src/test/java/com/pannk/demo/controller/HelloControllerMockTest.java
...va/com/pannk/demo/controller/HelloControllerMockTest.java
+40
-0
testing/src/test/java/com/pannk/demo/controller/HelloControllerTest.java
...t/java/com/pannk/demo/controller/HelloControllerTest.java
+36
-0
testing/src/test/java/com/pannk/demo/service/impl/CallServiceImplTest.java
...java/com/pannk/demo/service/impl/CallServiceImplTest.java
+30
-0
testing/src/test/java/com/pannk/demo/service/impl/HelloServiceImplTest.java
...ava/com/pannk/demo/service/impl/HelloServiceImplTest.java
+25
-0
未找到文件。
pom.xml
浏览文件 @
d933ea83
...
...
@@ -14,6 +14,7 @@
<module>
mms
</module>
<module>
integrate-mybatis
</module>
<module>
integrate-mybatisplus
</module>
<module>
testing
</module>
</modules>
<parent>
<groupId>
org.springframework.boot
</groupId>
...
...
testing/pom.xml
0 → 100644
浏览文件 @
d933ea83
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
springboot-demo
</artifactId>
<groupId>
com.pannk
</groupId>
<version>
1.0
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
testing
</artifactId>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
<exclusions>
<exclusion>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-api
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
\ No newline at end of file
testing/src/main/java/com/pannk/demo/App.java
0 → 100644
浏览文件 @
d933ea83
package
com.pannk.demo
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* Created by wolf on 20-11-10.
*/
@SpringBootApplication
public
class
App
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
App
.
class
,
args
);
}
}
testing/src/main/java/com/pannk/demo/controller/HelloController.java
0 → 100644
浏览文件 @
d933ea83
package
com.pannk.demo.controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* Created by wolf on 20-11-10.
*/
@RestController
public
class
HelloController
{
@RequestMapping
(
"/"
)
public
String
index
()
{
return
"index"
;
}
@RequestMapping
(
"/hello"
)
public
String
hello
()
{
return
"hello"
;
}
}
testing/src/main/java/com/pannk/demo/service/CallService.java
0 → 100644
浏览文件 @
d933ea83
package
com.pannk.demo.service
;
/**
* Created by wolf on 20-11-10.
*/
public
interface
CallService
{
/**
* 调用方法
*/
void
call
();
}
testing/src/main/java/com/pannk/demo/service/HelloService.java
0 → 100644
浏览文件 @
d933ea83
package
com.pannk.demo.service
;
/**
* Created by wolf on 20-11-10.
*/
public
interface
HelloService
{
/** hello
* @return
*/
String
hello
();
}
testing/src/main/java/com/pannk/demo/service/impl/CallServiceImpl.java
0 → 100644
浏览文件 @
d933ea83
package
com.pannk.demo.service.impl
;
import
com.pannk.demo.service.CallService
;
import
com.pannk.demo.service.HelloService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
* Created by wolf on 20-11-10.
*/
@Service
public
class
CallServiceImpl
implements
CallService
{
@Autowired
private
HelloService
helloService
;
@Override
public
void
call
()
{
System
.
out
.
println
(
"调用HelloService方法"
);
String
result
=
helloService
.
hello
();
System
.
out
.
println
(
"返回结果为:"
+
result
);
}
}
testing/src/main/java/com/pannk/demo/service/impl/HelloServiceImpl.java
0 → 100644
浏览文件 @
d933ea83
package
com.pannk.demo.service.impl
;
import
com.pannk.demo.service.HelloService
;
import
org.springframework.stereotype.Service
;
/**
* Created by wolf on 20-11-10.
*/
@Service
public
class
HelloServiceImpl
implements
HelloService
{
@Override
public
String
hello
(){
return
"hello"
;
}
}
testing/src/main/resources/application.yml
0 → 100644
浏览文件 @
d933ea83
testing/src/test/java/com/pannk/demo/controller/HelloControllerMockTest.java
0 → 100644
浏览文件 @
d933ea83
package
com.pannk.demo.controller
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.MvcResult
;
import
org.springframework.test.web.servlet.ResultActions
;
import
org.springframework.test.web.servlet.request.MockMvcRequestBuilders
;
import
java.net.URI
;
/**
* Created by wolf on 20-11-10.
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
MOCK
)
//MOCK为默认值,也可不设置
@AutoConfigureMockMvc
public
class
HelloControllerMockTest
{
@Autowired
private
MockMvc
mvc
;
@Test
public
void
testIndex
()
throws
Exception
{
ResultActions
ra
=
mvc
.
perform
(
MockMvcRequestBuilders
.
get
(
new
URI
(
"/"
)));
MvcResult
result
=
ra
.
andReturn
();
System
.
out
.
println
(
result
.
getResponse
().
getContentAsString
());
}
@Test
public
void
testHello
()
throws
Exception
{
ResultActions
ra
=
mvc
.
perform
(
MockMvcRequestBuilders
.
get
(
new
URI
(
"/hello"
)));
MvcResult
result
=
ra
.
andReturn
();
System
.
out
.
println
(
result
.
getResponse
().
getContentAsString
());
}
}
testing/src/test/java/com/pannk/demo/controller/HelloControllerTest.java
0 → 100644
浏览文件 @
d933ea83
package
com.pannk.demo.controller
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.test.context.junit4.SpringRunner
;
/**
* Created by wolf on 20-11-10.
* WebEnvironment.RANDOM_PORT会启动一个真实的Web容器,RANDOM_PORT表示随机端口
* 如果想使用固定端口,可配置为
* WebEnvironment.DEFINED_PORT,该属性会读取项目配置文件(如application.yml)中的端口(server.port)
* 如果没有配置,默认使用8080端口
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
public
class
HelloControllerTest
{
@Autowired
private
TestRestTemplate
restTemplate
;
@Test
public
void
testIndex
(){
String
result
=
restTemplate
.
getForObject
(
"/"
,
String
.
class
);
Assert
.
assertEquals
(
"index"
,
result
);
}
@Test
public
void
testHello
(){
String
result
=
restTemplate
.
getForObject
(
"/"
,
String
.
class
);
Assert
.
assertEquals
(
"Hello world"
,
result
);
//这里故意写错
}
}
\ No newline at end of file
testing/src/test/java/com/pannk/demo/service/impl/CallServiceImplTest.java
0 → 100644
浏览文件 @
d933ea83
package
com.pannk.demo.service.impl
;
import
com.pannk.demo.service.CallService
;
import
com.pannk.demo.service.HelloService
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.BDDMockito
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.test.context.junit4.SpringRunner
;
/**
* Created by wolf on 20-11-10.
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
CallServiceImplTest
{
@MockBean
private
HelloService
helloService
;
@Autowired
private
CallService
mainService
;
@Test
public
void
testCall
(){
BDDMockito
.
given
(
this
.
helloService
.
hello
()).
willReturn
(
"hello world"
);
mainService
.
call
();
}
}
testing/src/test/java/com/pannk/demo/service/impl/HelloServiceImplTest.java
0 → 100644
浏览文件 @
d933ea83
package
com.pannk.demo.service.impl
;
import
com.pannk.demo.service.HelloService
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
/**
* Created by wolf on 20-11-10.
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
NONE
)
public
class
HelloServiceImplTest
{
@Autowired
private
HelloService
helloService
;
@Test
public
void
testHello
(){
String
result
=
helloService
.
hello
();
System
.
out
.
println
(
result
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录