06 2020 档案
摘要:环境 JDK 8 Spring Tool Suite 4.6.1 Maven 3.6.3 JSEncrypt 2.3.1 概述 前端 JavaScript 使用 RSA 的公钥加密,后端 Java 使用私钥进行解密。 pom.xml <project xmlns="http://maven.apac
阅读全文
摘要:环境 JDK 8 Spring Tool Suite 4.6.1 Maven 3.6.3 概述 使用 Java 进行 RSA 的加密和解密。 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://ww
阅读全文
摘要:环境 JDK 8 Spring Tool Suite 4.6.1 Maven 3.6.3 概述 使用 RSA 算法生成公钥和私钥。 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.
阅读全文
摘要:环境 JDK 8 Spring Tool Suite 4.6.1 Spring Boot 1.5.22.RELEASE Maven 3.6.3 概述 使用 Spring WebMvc 的时候,经常返回的内容包括 json 和 xml 和视图,下面给出直接在 controller 中返回文本的示例。
阅读全文
摘要:环境 JDK 11 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 与 maven 集成 因为已经是 maven 项目了,所以不再需要任何东西,默认就与 maven 集成了。 不过由于 maven-surefire-plugin 自身的缺陷,导致测试时,
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 Category 分类用于在测试中添加元数据,鼓励像下面这样使用分类测试: 自动化测试的类型: UnitTests, IntegrationTests, SmokeTests, Regre
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 Theory 这些都是实验性质的,可以不了解。 @ParametersSuppliedBy 可以编写自己提供数据的方式,不过需要实现 ParameterSupplier 接口。 理论示例
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 Theory 这些都是实验性质的,可以不了解。 Theory 相比 Test 更加的灵活。 其中 @DataPoint 的名称和 @FromDataPoints 的名称对应,只会注入对应的
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 假设 Assumptions 即假设,JUnit 用它来确定条件满足的情况下才执行测试,否则就直接忽略。 如果是在 @Before 或者 @BeforeClass 方法中,和放在 @Tes
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 参数化测试 参数化测试首先需要指定 Runner:org.junit.runners.Parameterized,然后准备测试数据。 有两种注入测试数据的方法,一种是构造函数注入,另一种是
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 方法执行顺序 查看官方原文 根据设计,JUnit不指定测试方法调用的执行顺序。 到目前为止,仅按反射 API 返回的顺序依次用这些方法。 但是,使用JVM顺序是不明智的,因为 Java 平
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 断言 在程序设计中,断言(assertion)是一种放在程序中的一阶逻辑(如一个结果为真或是假的逻辑判断式),目的是为了标示与验证程序开发者预期的结果-当程序运行到断言的位置时,对应的断言
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 断言 在程序设计中,断言(assertion)是一种放在程序中的一阶逻辑(如一个结果为真或是假的逻辑判断式),目的是为了标示与验证程序开发者预期的结果-当程序运行到断言的位置时,对应的断言
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 说明 异常测试在 4.13 之前也有,都有一点缺点,不推荐使用,推荐使用 4.13 之后的 assertThrows。 异常测试示例 pom.xml <project xmlns="htt
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 说明 测试超时有两种方式,一种是使用 @Test 注解的 timeout 属性,另一种是使用 @Rule。 两种方式有一点区别,其中 @Test 方式运行的,测试方法和 @Before @
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 Rules 官网描述如下: Rules allow very flexible addition or redefinition of the behavior of each test
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 Rules 官网描述如下: Rules allow very flexible addition or redefinition of the behavior of each test
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 @Ignore 注解 使用 @Ignore 注解可以忽略一个或者一组单元测试,并且可以提供忽略的说明。 Ignore 示例 pom.xml <project xmlns="http://m
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 测试套件 测试套件可以将多个测试类组合到一起运行。 Test Suite 示例 pom.xml <project xmlns="http://maven.apache.org/POM/4.
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 main 方法运行测试 除了和 IDE 继承,右键运行之外,还可以通过 main 运行测试,并且得到运行的结果数据。 官网上将这种方式叫做基于控制台的 Runner(Console bas
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 IDE 支持 在 IDE 中,比如 NetBeans, Eclipse and IntelliJ IDEA 都内置了图形化的 JUnit Runner 的支持,可以直接运行。 在当前版本,
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 顺序注解 可以参与到执行过程中的注解一共有四个,分别是: @BeforeClass:在当前测试类的所有测试执行之前执行,比 @Before 更早执行。 @AfterClass:在当前测试类
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 Test Fixture Test Fixture 是官方给出的一个概念,原文如下: A test fixture is a fixed state of a set of objects
阅读全文
摘要:环境 JDK 6 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 什么是 JUnit 以下是来自官网的一段话: What is JUnit? JUnit is a simple, open source framework to write and ru
阅读全文
摘要:以下内容参考 stackoverflow 先说结论,通过 HttpServletResponse 得到的 PrintWriter 和 ServletOutputStream 不需要手动关闭。 回答 Normally you should not close the stream. The servl
阅读全文
摘要:以下资料全部来源于维基百科 servlet 2.5 的 api 基本上都学习完了,这里对 servlet 做一个小结。 Java Servlet Servlet(Server Applet),全称Java Servlet,未有中文译文,是用Java编写的服务器端程序。 其主要功能在于交互式地浏览和修
阅读全文
摘要:环境 JDK 8 Spring Tool Suite 4.6.1 Servlet 3.1 Tomcat 8.5 Maven 3.6.3 RequestDispatcher 说明 RequestDispatcher 定义了很多和跳转路径相关的属性, 这里可以不用关心,主要是服务器的实现需要关心这些属性
阅读全文
摘要:环境 JDK 8 Spring Tool Suite 4.6.1 Servlet 3.1 Tomcat 8.5 Maven 3.6.3 HttpSessionBindingListener 说明 HttpSessionBindingListener 可以监听实现了该接口的对象在 Session 中被
阅读全文
摘要:环境 JDK 8 Spring Tool Suite 4.6.1 Servlet 3.1 Tomcat 8.5 Maven 3.6.3 概述 域对象中属性的监听器,可以监听属性的设置、改变和移除。 一共有三个,这里以 ServletRequestAttributeListener 为例学习。 Ser
阅读全文
摘要:环境 JDK 8 Spring Tool Suite 4.6.1 Servlet 3.1 Tomcat 8.5 Maven 3.6.3 概述 域对象监听器,可以监听对象的创建和销毁。 一共有三个,这里以 ServletRequestListener 为例学习。 ServletRequestListe
阅读全文