我看到一些人遇到了这个问题,并且已经挣扎了几个星期,但无法在同一个项目上运行 JUnit4 和 JUnit5(我需要它来维护一些旧的测试)。我注意到,如果删除 Maven Surefire 插件,我可以运行 JUnit4 测试,而当它添加到 POM 时,只能运行 JUnit5 测试。
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
这种依赖关系也会发生类似的情况。如果我将它添加到 POM 文件中,即使有 Maven Surefire 插件,我也可以运行 JUnit4 测试。但是,我需要删除它才能运行 JUnit5 测试。
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这是我完整的pom
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hmhco</groupId>
<artifactId>tests</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
<maven.compiler.version>3.8.1</maven.compiler.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<rest-assured.version>3.0.0</rest-assured.version>
<json-schema-validator.version>3.3.0</json-schema-validator.version>
<junit5.version>5.2.0</junit5.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId> …Run Code Online (Sandbox Code Playgroud) 如何使用 Espresso 检查 RecyclerView 项目是否以正确的顺序显示?我正在尝试通过文本检查每个元素的标题来测试它。
当我尝试这段代码时,它可以单击该元素,但无法继续执行单击来尝试断言该元素的文本
onView(withId(R.id.rv_metrics)).perform(actionOnItemAtPosition(0, click()));
Run Code Online (Sandbox Code Playgroud)
当我尝试使用自定义匹配器时,我不断收到错误消息
Error performing 'load adapter data' on view 'with id: mypackage_name:id/rv_metrics'
Run Code Online (Sandbox Code Playgroud)
我现在知道了,onData doesn't work for RecyclerView但在此之前我曾尝试使用自定义匹配器来完成此任务。
public static Matcher<Object> hasTitle(final String inputString) {
return new BoundedMatcher<Object, Metric>(Metric.class) {
@Override
protected boolean matchesSafely(Metric metric) {
return inputString.equals(metric.getMetric());
}
@Override
public void describeTo(org.hamcrest.Description description) {
description.appendText("with title: ");
}
};
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过这样的事情,但由于作为 actionOnItemAtPosition 方法的参数给出的类型,它显然不起作用,但我们是否有类似的东西可以工作?
onView(withId(R.id.rv_metrics)).check(actionOnItemAtPosition(0, ViewAssertions.matches(withText("Weight"))));
Run Code Online (Sandbox Code Playgroud)
请问我在这里缺少什么?非常感谢。
我正在尝试使用 Espresso 断言是否在 Android 中的图像视图上显示了正确的图像。图像以 SVG 格式提供,并使用 Android Studio 转换器直接转换为可绘制的矢量。我的自定义匹配器对某些图像进行了成功的测试,但对其他图像却没有。如果我交换 SVG XML 文件,那么结果会与现在失败的结果相反,这让我怀疑这可能与检查 SVG 本身有关,这可能是由于某些路径的字符数量,就像我delete some lines那样包含比其他字符更多的字符,但不确定如何正确修复它。
这是有效的SVG
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="80dp"
android:height="80dp"
android:viewportWidth="80"
android:viewportHeight="80">
<path
android:pathData="M37.2,37.1m-34.85,0a34.85,34.85 0,1 1,69.7 0a34.85,34.85 0,1 1,-69.7 0"
android:fillColor="#fff"/>
<path
android:pathData="M49.22,19.23h2.67A4.79,4.79 0,0 1,56.67 24V53.39a4.79,4.79 0,0 1,-4.78 4.77H22.51a4.79,4.79 0,0 1,-4.78 -4.77V24a4.79,4.79 0,0 1,4.78 -4.77h3.2"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M45.37,24.93a8.9,8.9 0,1 1,-8.9 -8.9A8.9,8.9 0,0 1,45.37 24.93Z"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M35.88,25.46L40.08,21.72"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
</vector>
Run Code Online (Sandbox Code Playgroud)
但这是不起作用的SVG
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="80dp" …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用从另一个登录调用中检索到的 sif 令牌更新我的 api 的标头。我知道如何在 Postman 中执行此操作,方法是转到“测试”选项卡并在那里为登录 api 添加类似的内容,这将设置我的全局变量。
var data = JSON.parse(responseBody);
postman.setGlobalVariable("SIF_TEACHER", data.sifToken);
Run Code Online (Sandbox Code Playgroud)
但是,我从他们的官方支持页面阅读了本教程,但无法真正理解它,也找不到有关链接请求的任何其他文档。如果有人愿意分享更详细的步骤来执行此操作,或者请指点我有关该主题的一些文档?
非常感谢。
我有一个控制器,它向用户提供 403 响应,除非他们使用 JWT 令牌进行身份验证,该令牌通过授权标头作为不记名令牌传递。我正在寻找有关如何使用 Mockito 进行测试的资源,但到目前为止我还不是很成功,因为他们中的大多数人告诉我使用 @WithMockUser 注释,我知道这是为了 Spring 安全性,是的,但不包括模拟对于 JWT 令牌。我尝试过模拟一些对象,例如 UserDetailsClass 和 JwtFilter,甚至对不记名令牌进行硬编码,但我认为应该有更多内容。
@MockBean
private CategoryCommandService categoryCommandService;
@Autowired
private MockMvc mockMvc;
@MockBean
private MyUserDetailsService myUserDetailsService;
@MockBean
private CategoryRepository categoryRepository;
@MockBean
private JwtUtil jwtUtil;
@Autowired
private JwtRequestFilter filter;
@Test
void testCreateCategory() throws Exception {
CategoryCreateDto categoryCreateDto = new CategoryCreateDto("category");
CategoryCreateDto categoryCreateResponseDto = new CategoryCreateDto(UUID.fromString("2da4002a-31c5-4cc7-9b92-cbf0db998c41"), "category");
String jsonCreate = asJsonString(categoryCreateDto);
String jsonResponse = asJsonString(categoryCreateResponseDto);
RequestBuilder request = MockMvcRequestBuilders
.post("/api/adverts/category")
.content(jsonCreate)
.header("Authorization", "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmb29AZW1haWwuY29tIiwiZXhwIjoxNjM4ODU1MzA1LCJpYXQiOjE2Mzg4MTkzMDV9.q4FWV7yVDAs_DREiF524VZ-udnqwV81GEOgdCj6QQAs")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON);
mockMvc.perform(request).andReturn();
when(categoryCommandService.createCategory(categoryCreateDto)).thenReturn(
categoryCreateResponseDto);
MvcResult …Run Code Online (Sandbox Code Playgroud) 我对 React 非常陌生,我正在尝试为底部栏上的非活动选项卡设置文本和其他样式的颜色,但已经使用了几个小时并且无法使其工作,因为文本不会出现,除非这是选定的选项卡。我正在使用createMaterialBottomTab。
如果我能得到任何帮助,这是我的整个屏幕:
import React from 'react'
import { Platform, Text, View } from 'react-native'
import { createAppContainer } from 'react-navigation'
import { createBottomTabNavigator } from 'react-navigation-tabs'
import { createStackNavigator } from 'react-navigation-stack'
import { createMaterialBottomTabNavigator } from 'react-navigation-material-bottom-tabs'
import HeadlinesScreen from '../screens/HeadlinesScreen'
import IrelandScreen from '../screens/IrelandScreen'
import TechnologyScreen from '../screens/TechnologyScreen'
const defaultStackNavOptions = {
headerStyle: {
backgroundColor: '#4a148c'
},
headerTintColor: 'white',
}
const NewsNavigator = createStackNavigator(
{
Headlines: HeadlinesScreen,
Ireland: IrelandScreen,
Technology: TechnologyScreen
})
const HeadLinesNavigator …Run Code Online (Sandbox Code Playgroud) 我需要使用 Pact 测试和 REST Assured 检查类型为 /meeting/id 的 api。id 可能会改变,我想在测试之前创建一个项目并注入他们的 id 以覆盖设置为合同 url 路径的一部分的内容,但不确定如何去做?
这是我的消费者:
@ExtendWith(PactConsumerTestExt.class)
public class PactConsumerTest {
Map<String, String> headers = new HashMap<>();
String storeMeetingPath = "/meeting/256";
@Pact(provider = VC, consumer = ED_UI)
public RequestResponsePact createPact(PactDslWithProvider builder) {
headers.put("Content-Type", "application/json");
headers.put("Accept", "application/json");
return builder
.given("A request to retrieve a meeting for a user")
.uponReceiving("A request to retrieve a meeting for a user")
.path(storeMeetingPath)
.method("GET")
.headers(headers)
.willRespondWith()
.body(new PactDslJsonBody()
.integerType("meetingId", 3)
.stringType("meetingTitle", "My title")
.stringType("meetingDescription", "My description"))
.status(200) …Run Code Online (Sandbox Code Playgroud) 我有一个使用 Groupie 库实现的 RecyclerView,我可以从列表中删除一个项目,但需要更新视图才能看到更改。我想要使用像notifyDataSetChanged() 这样的东西,这样列表就会立即更新。不过,我在这个阶段有点困惑,尝试了几种不同的方法来从托管我的视图持有者的类中获取接口,以便从持有适配器的片段触发,但我想如果我能得到的话,我现在就陷入困境了请帮忙。
class RecyclerProductItem(
private val activity: MainActivity,
private val product: Product, private val adapterListener: AdapterListener
) : Item<GroupieViewHolder>() {
companion object {
var clickListener: AdapterListener? = null
}
override fun bind(viewHolder: GroupieViewHolder, position: Int) {
viewHolder.apply {
with(viewHolder.itemView) {
clickListener = adapterListener
ivTrash.setOnClickListener(object : View.OnClickListener {
override fun onClick(v: View?) {
if (clickListener != null) {
Toast.makeText(context, "delete method to be added here", Toast.LENGTH_SHORT).show()
clickListener?.onClickItem(position)
}
}
})
}
}
}
override fun getLayout() = R.layout.recyclerview_item_row …Run Code Online (Sandbox Code Playgroud) 我对 React 非常陌生,第一次尝试通过将其推送到历史记录来实现到新页面的导航,但现在我在这个错误上Cannot read property 'push' of undefined for react use history停留了几个小时,我认为我需要一些帮助或指导。
这是我的小型 mvp 组件(我正在使用 Hooks):
import React, {useEffect, useState} from 'react';
import {BrowserRouter as Router, Route, Switch, useHistory} from "react-router-dom";
import Report from "./components/Report";
function App() {
let history = useHistory();
function handleClick() {
history.push("/report");
}
return (
<Router>
<Route path="/report" component={Report}/>
<div>
<button onClick={handleClick}>Click me</button>
</div>
</Router>
);
}
export default App
Run Code Online (Sandbox Code Playgroud)
和
import React from "react";
import {withRouter} from "react-router-dom";
const …Run Code Online (Sandbox Code Playgroud) Current request is not a multipart request当尝试为我的请求上传 json 文件和额外的 id 或 dto 对象时,我收到此错误,因为这也需要填充我的数据库。
当我只发送 json 文件时,所有内容都上传得很好,但现在我已将 id 字段添加到相关方法和 Postman 中,我收到此消息并努力调试和修复它,如果我能得到任何请帮助。
这些是涉及的部分:
@Controller
@RequestMapping("/api/gatling-tool/json")
public class StatsJsonController {
@Autowired
StatsJsonService fileService;
@PostMapping(value = "/import")
public ResponseEntity<ResponseMessage> uploadFile(@RequestParam("file") MultipartFile file, @RequestBody CategoryQueryDto categoryQueryDto) {
String message = "";
UUID id = categoryQueryDto.getId();
if (StatsJsonHelper.hasJsonFormat(file)) {
try {
fileService.save(file, id);
message = "Uploaded the file successfully: " + file.getOriginalFilename();
return ResponseEntity.status(HttpStatus.OK).body(new ResponseMessage(message));
} catch (Exception e) {
message = "Could not upload …Run Code Online (Sandbox Code Playgroud) 我仍然在我的 Kotlin 项目中使用 Butterknife,但仅用于绑定颜色和可绘制对象,因为绑定视图不需要它。但是,将我的项目更新到 AndroidX 后,我无法再使用该库。
这就是我所拥有的
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
kapt {
generateStubs = true
}
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
kapt 'androidx.databinding:databinding-compiler:3.5.0-alpha02'
kapt 'com.android.tools.build.jetifier:jetifier-core:1.0.0-beta02'
ext.kotlin_version = '1.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
AS 3.3.1
Run Code Online (Sandbox Code Playgroud)
并这样称呼他们
@JvmField
@BindColor(R.color.just_pink)
var pink: Int = 0
@JvmField
@BindDrawable(R.drawable.rectangle_pink_btn_all_radius)
var rectanglePinkAllRadius: Drawable? = null
Run Code Online (Sandbox Code Playgroud)
确保我有Butterknife.bind(this, view)onCreate 方法。
谢谢你的帮助。
java ×5
android ×4
kotlin ×2
spring-boot ×2
automation ×1
butterknife ×1
content-type ×1
cucumber ×1
insomnia ×1
junit ×1
junit4 ×1
junit5 ×1
jwt ×1
maven ×1
mockito ×1
pact ×1
pact-jvm ×1
postman ×1
react-hooks ×1
react-native ×1
react-navigation-bottom-tab ×1
react-router ×1
reactjs ×1
report ×1
rest ×1
svg ×1