junit

Ant -----ant标签和自定义任务

懵懂的女人 提交于 2021-02-04 04:26:01
随便记一下 Ant的用法吧。ant ,maven, gradle ,三个打包工具到齐了,Ant 常见标签解析,ant 自定义task 。 <?xml version="1.0" encoding="UTF-8"?> <project name="pase2" default="allElements"> <property environment="env" /> <!-- ===================================================================== --> <!-- Run a given ${target} on all elements being built --> <!-- Add on <ant> task for each top level element being built. --> <!-- ===================================================================== --> <available property="allElementsFile" file="${builder}/allElements.xml" value="${builder}/allElements.xml"/> <property name=

maven打包时跳过测试

徘徊边缘 提交于 2021-02-02 18:41:08
方法一:修改pom.xml文件 <project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build> [...] </project> 方法二:在Terminal执行命令 mvn install -DskipTests 方法三:在Terminal执行命令 mvn install -Dmaven.test.skip=true 方法四:Spring boot项目使用 spring-boot-maven-plugin插件已经集成了maven-surefire-plugin插件,会自动运行 junit test ,只需要在pom.xml里增加如下配置: <properties> <!-- 跳过测试 --> <skipTests>true</skipTests> </properties> 来源: oschina 链接: https://my.oschina.net

Postman+Newman+Git+Jenkins实现接口自动化测试持续集成

这一生的挚爱 提交于 2021-02-01 08:02:55
接口测试脚本一般的执行流程 做接口测试的话,首先要考虑的是如何选择一个合适的工具? 在忽略工具是否好用,是否能满足业务要求的前提下,需要考虑以下2点: 1、要考虑工具的学习成本 2、要考虑团队的协作  接口测试脚本的执行流程: 团队成员协作编写接口用例->用例归档到git/svn->脚本集成jenkins,在环境更新后自动触发执行或定时执行。 Postman工具常见的接口测试流程是怎样的? 使用Postman+Newman+Git+Jenkins+钉钉 /邮件提醒 Windows系统Newman安装 1、下载Node.js进行安装,然后配置node的环境变量 2、借助npm工具,安装Newman npm install -g newman 3、运行Newman 通过Newman来运行某个postman脚本: newman run mycollection.json 用newman执行postman脚本的效果如下: Centos系统Newman安装 1、先下载安装nodejs ( 必须安装10.0以上的版本 ) 从http://nodejs.cn/download/下载linux系统压缩包 ,,解压,配置环境变量 tar xvJf ***.tar.xz echo "export PATH=\"\$PATH:/root/tools/node-v14.8.0-linux-x64/bin\

从Java角度修复SQL注入漏洞

南笙酒味 提交于 2021-02-01 05:27:15
   很多情况因为过滤不严导致很多网站存在sql注入,这里以用户登陆为例,简单举例        首先创建一个测试的数据库         比较基础,不写创建过程了                java代码如下:          package cn.basic.jdbc; import java.awt.image.RescaleOp; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import org.junit.jupiter.api.Test; public class Test1 { /* * public static void main(String[] args) throws ClassNotFoundException, * SQLException { login("aa","aa"); } */ @Test public void testlogin() throws ClassNotFoundException, SQLException {

Jenkins+maven+jmeter+eclipse搭建自动化测试平台

人盡茶涼 提交于 2021-01-31 23:48:42
一、准备工作 1、jmeter准备测试脚本 2、maven环境配置 3、eclipse创建maven项目 4、Jenkins集成项目 二、jmeter准备测试脚本 使用jmeter准备测试脚本(不管录制也好还是自己手动配置也好都可以) 三、maven环境配置 1、下载maven 下载地址:http://maven.apache.org/download.cgi 2、下载之后解压 3、配置环境变量 MAVEN_HOME:C:\Program Files\Java\apache-maven-3.6.0 解压之后的目录 在Path变量加上:%MAVEN_HOME%\bin; 注:环境变量内一定是要配置好jdk的环境 在命令行下输入 mvn -v 显示出以下信息表示配置成功 四、eclipse配置maven项目 1、eclipse内创建maven项目 File—>New—>Project 然后选择maven项目 然后选择默认工作区间后点击Next 点击Next 填写Group Id和Artifct Id后点击Finish 创建成功之后生成目录如下 修改pom.xml,代码如下: < project xmlns ="http://maven.apache.org/POM/4.0.0" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"

JUnit for void delete method

自作多情 提交于 2021-01-29 21:16:42
问题 I am new to JUnit and trying to learn. How can we write a JUnit for a void method. I have a delete method which is void. I am writing the test like below but its not working. Please suggest. Method for which I have to write test case. public class DoseService { @Autowired private DoseRepository doseRepo; public void deleteDose(int id) { doseRepo.deleteById(id); } } My Test @Autowired private DoseService doseService; @MockBean public DoseRepository doseRepository; @Test public void

Needing help trying to Format DateTime

徘徊边缘 提交于 2021-01-29 20:11:48
问题 So for my assignemtn,I am instructed to create unit tests for Shopify integration. One of my assert methods require me to format the date a certain way. My assert method is this and the following trace is as follows. It's really difficult trying to keep up with the documentations. assertEquals((new Date(2020, 7, 23)),order.getCreatedAt()); java.lang.AssertionError: expected:<Mon Aug 23 00:00:00 EDT 3920> but was:<2020-07-23T11:47:45.000-04:00> 回答1: I suggest you switch from the outdated and

EasyMock - override an object creation

喜夏-厌秋 提交于 2021-01-29 18:06:19
问题 How can I override an object creation inside a method? public class ClassToTest { public Object testMethod() { ... code ... Object result; try { result = new ClassToMock(someParam).execute(); } catch (Exception e) { // handle error } return result; } } How can my test override the "execute" method of ClassToMock? I will be happy for code examples with EasyMock. I want to test "testMethod", something like: @Test public void testMethodTest(){ ClassToTest tested = new ClassToTest(); // Mock

surefire results not showing in the test tab of gitlab CI/CD

我是研究僧i 提交于 2021-01-29 17:39:05
问题 I have a java-maven application and I am trying to display my junit results on gitlab as shown in the gitlab help here: https://docs.gitlab.com/ee/ci/junit_test_reports.html#viewing-junit-test-reports-on-gitlab I added the maven-surefire-plugin in the pom build and the maven-surefire-report-plugin in the pom reporting section. I checked that it works because the surefire-report.html is correctly created in my local target repository, with the test results. Then i configured my gitlabci.yaml

Spring LocaleContextHolder not correctly set

给你一囗甜甜゛ 提交于 2021-01-29 17:13:13
问题 I'm having some issues with Spring LocaleContextHolder . I have the following code: public void sendPasswordRecoverySmsAsync(String phone) { CompletableFuture.runAsync(() -> { sendPasswordRecoverySmsSync(phone); }); } public void sendPasswordRecoverySmsSync(String phone) { User user = userDao.findByPhone(phone, User.class).orElseThrow(() -> new UserNotFoundException(phone)); log.info("User found, recovering password"); user.setUpdateTime(LocalDateTime.now()); userDao.save(user); int otp =