我有一个 Spring Boot 应用程序,可生成大量控制器,我的目标是为特定控制器创建集成测试。我读到我们可以使用注释实现测试切片,@WebMvcTest该注释仅加载部署目标控制器所需的内容,这个假设正确吗?这是我的测试:
@RunWith(SpringRunner.class)
@WebMvcTest(
controllers = {DummyController.class},
)
public class DummyControllerIT {
@Autowired
private MockMvc mockMvc;
...
Run Code Online (Sandbox Code Playgroud)
不幸的是,执行尝试部署与目标控制器无关的其他控制器/服务/存储库,这迫使我使用@MockBean它们中的每一个。我的印象是,这@WebMvcTest将使我不必拥有带有@MockBean注释的声明的控制器/服务/存储库的广泛列表,我错了吗?
@MockBean如果我误解了这一点并且我希望在应用程序的不相关部分上使用,那么为什么最好使用@WebMvcTest而不是@SpringBootTest?另一方面,如果我正确地解释了它,我错过了什么?
不确定它是否相关,但这是我的初始化程序:
@ComponentScan(scopedProxy = ScopedProxyMode.INTERFACES)
@SpringBootApplication
@EnableTransactionManagement
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableScheduling
@EnableCaching
@EnableJpaAuditing
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
public class Application extends SpringBootServletInitializer {
@Autowired
private Environment env;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { …Run Code Online (Sandbox Code Playgroud) 所以我有两段Java代码。一个是一小段简单的源代码,另一个是我试图弄乱的 JUnit 测试类。但是,每当我想要调试代码以确保这个简单的代码正确显示时,我都会在 java.util.ArrayList.forEach(ArrayList.java:1507) 错误处收到 NullPointerException。
这是我的源代码:
public class sourceCode {
public int mid(int x, int y, int z) {
int m = z;
if (y < z) {
if (x < y) {
m = y;
}
else if (x < z) {
m = x;
}
}
else {
if (x > y) {
m = y;
}
else if (x > z) {
m = x;
}
}
return m;
}
Run Code Online (Sandbox Code Playgroud)
}
这是我的 JUnit 测试用例代码:
import static …Run Code Online (Sandbox Code Playgroud) 我创建了一个 maatwebsite/excel 导入例程,我想测试它。
maatwebsite/excel 测试页面除了伪造之外没有向我提供任何其他信息。但我需要上传我的真实 Excel 文件,因为我想验证 Excel 文件中的数据是否已正确处理。
这是我的上传输入字段和用于点击端点的相应按钮/import
<form action="/import" method="post" enctype="multipart/form-data">
@csrf
<div class="form-group">
<input type="file" class="form-control-file file-path" name="fileToUpload">
</div>
<button type="submit" class="btn btn-primary">Import File</button>
</form>
Run Code Online (Sandbox Code Playgroud)
在视图的控制器端,将处理并导入上传的文件。
...
public function store(Request $request) {
$request->validate([
'fileToUpload' => 'required|file|max:4096|mimes:xls,xlsx',
]);
// start the import
Excel::import(new SheetNavigator, request()->file('fileToUpload'));
...
Run Code Online (Sandbox Code Playgroud)
需要导入的文件位于我的测试环境中:
/tests
/files
/myexcel.xlsx
Run Code Online (Sandbox Code Playgroud)
public function test_user_can_import_file() {
Excel::fake();
$datafile = new UploadedFile(
base_path('tests/files/myfile.xlsx'),
'myfile.xlsx',
'xlsx',
13071,
true);
$res = $this->post('/import', [
'fileToUpload' => $datafile
]);
// asserting, that everything …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 bean 中运行 Vault 容器,并使用它来创建 VaultTemplate bean 以进一步在测试中使用
@TestConfiguration
@TestPropertySource("classpath:application.yml")
public class TestsConfiguration {
@Container
public static VaultContainer vaultContainer = new VaultContainer();
@Bean
@Order(1)
public VaultEndpoint vaultEndpoint() {
vaultContainer
.withVaultToken("00000000-0000-0000-0000-000000000000")
.withExposedPorts(8200);
vaultContainer.start();
return VaultEndpoint.create(vaultContainer.getContainerIpAddress(), vaultContainer.getMappedPort(8200));
}
@Bean
@Order(2)
public VaultTemplate vaultTemplate(VaultEndpoint vaultEndpoint) {
return new VaultTemplate(vaultEndpoint, new TokenAuthentication("00000000-0000-0000-0000-000000000000"));
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试通过 VaultOperations 编写一些 kv 时,我得到:
“https://localhost:32998/v1/my/secret”的 GET 请求出现 I/O 错误:无法识别的 SSL 消息,纯文本连接?;嵌套异常是 javax.net.ssl.SSLException:无法识别的 SSL 消息,纯文本连接?
我怎么解决这个问题?
我有一个 Testcafe 脚本 ( script.js)。我想在 Chrome 浏览器上运行它,但以无头模式运行。所以,我使用以下命令。
testcafe chrome:headless script.js
Run Code Online (Sandbox Code Playgroud)
这很好用。但是,现在我希望对其进行 Docker 化并在容器中运行它。目的是让它在 Kubernetes 中运行。我怎样才能实现这个目标?
我看到Testcafe Docker 镜像,但这只是为了运行 Testcafe 实例。它不能满足我在容器中的 Chrome Headless 中运行此脚本的要求。
(这个问题和我问的不一样)
我的部署成功了
useLocation
/Users/hvaandres/Desktop/Development/Ecommerce/modules/hooks.js:29
26 | );
27 | }
28 |
> 29 | return useContext(Context).location;
30 | }
31 |
32 | export function useParams() {
Run Code Online (Sandbox Code Playgroud)
成功:
Compiled successfully!
You can now view ecommerce-store in the browser.
Local: http://localhost:3000
On Your Network: http://192.168.1.194:3000
Note that the development build is not optimized.
To create a production build, use npm run build.
Run Code Online (Sandbox Code Playgroud)
该问题表明该问题来自 hook.js 文件,但我在存储库中没有看到该文件:
如果我查看 chrome 工具,这是我的问题的参考
import React from "react";
import invariant from "tiny-invariant";
import Context from "./RouterContext.js";
import …Run Code Online (Sandbox Code Playgroud) 每次调用相同的wiremock端点时,我需要从预定义的集合中返回随机响应。我该怎么做?
这是我第一次测试 flutter 应用程序。HomeView我尝试用这个测试代码来泵:
void main() {\n group('Home Test', () {\n _pumpHome(WidgetTester tester) => tester.pumpWidget(\n MaterialApp(\n home: HomeView(),\n ),\n );\n\n testWidgets('Route to Azkar page', (WidgetTester tester) async {\n await _pumpHome(tester);\n await tester.tap(find.byKey(Key('morning')));\n expect(find.byType(ListView), findsOneWidget);\n });\n });\n}\nRun Code Online (Sandbox Code Playgroud)\n但这两个例外却发生了。
\n\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY WIDGETS LIBRARY \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following LateError was thrown building HomeView(dirty):\nLateInitializationError: Field '_instance@99075166' has not been initialized.\n\nThe relevant error-causing widget was:\n HomeView file:///E:/projects/flutterProject/tafra/test/home_test.dart:26:19\n\nWhen the exception was thrown, this was the stack:\n#0 ScreenUtil._instance (package:flutter_screenutil/screen_util.dart)\n#1 new ScreenUtil (package:flutter_screenutil/screen_util.dart:28:12)\n#2 SizeExtension.w …Run Code Online (Sandbox Code Playgroud) testing unit-testing flutter flutter-test widget-test-flutter
我已经有一个工作项目,几乎没有通过赛普拉斯测试。现在我正在尝试使用 Cypress + Pact 添加合约测试
在开发人员控制台中,我可以看到应用程序正在调用/api/v1/document-service,但我得到:
协议验证失败 - 预期交互与实际不符。
部分日志:
W, [2021-07-20T12:49:37.157389 #34805] WARN -- : Verifying - actual interactions do not match expected interactions.
Missing requests:
POST /api/v1/document-service
W, [2021-07-20T12:49:37.157489 #34805] WARN -- : Missing requests:
POST /api/v1/document-service
Run Code Online (Sandbox Code Playgroud)
我在用着:
cypress: 7.5.0
@pact-foundation/pact: 9.16.0
Run Code Online (Sandbox Code Playgroud)
我已完成的步骤:
添加了 cypress 插件(https://github.com/pactflow/example-consumer-cypress/blob/master/cypress/plugins/cypress-pact.js)
添加了命令(https://github.com/pactflow/example-consumer-cypress/blob/master/cypress/support/commands.js)
将配置添加到 cypress.json ( https://github.com/pactflow/example-consumer-cypress/blob/master/cypress.json ) - 如果我不想与真实服务器交互,则不确定要添加到 baseUrl 中的内容。
添加测试:
let server;
describe('Simple', () => {
before(() => {
cy.mockServer({
consumer: 'example-cypress-consumer',
provider: 'pactflow-example-provider',
}).then(opts …Run Code Online (Sandbox Code Playgroud)我有一个非常大的 JSON 对象数组。我需要对每个单独的元素运行 Jest 测试。我尝试首先迭代数组,然后在循环中编写测试,如下所示:
describe("Tests", (f) => {
it("has all fields and they are valid", () => {
expect(f.portions! >= 0).toBeTruthy();
expect(f.name.length > 0 && typeof f.name === "string").toBeTruthy();
});
it("has an image", () => {
expect(f.image).toBeTruthy();
});
});
Run Code Online (Sandbox Code Playgroud)
然而,对于这段代码,Jest 抱怨“你的测试套件必须至少包含一个测试”。
我是否必须为每个测试循环遍历这个数组?
testing ×10
java ×3
javascript ×3
node.js ×2
unit-testing ×2
arraylist ×1
containers ×1
contract ×1
cypress ×1
docker ×1
e-commerce ×1
flutter ×1
flutter-test ×1
jestjs ×1
junit ×1
kubernetes ×1
laravel ×1
pact ×1
phpunit ×1
reactjs ×1
spring ×1
spring-boot ×1
spring-vault ×1
testcafe ×1
ts-jest ×1
wiremock ×1