嘿,我在创建测试用例时开始使用 spring boot 测试框架学习 spring-boot junit 测试,我面临以下问题。
如何解决这个问题。
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
at org.springframework.util.Assert.state(Assert.java:70)
at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.getOrFindConfigurationClasses(SpringBootTestContextBootstrapper.java:202)
at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.processMergedContextConfiguration(SpringBootTestContextBootstrapper.java:137)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:409)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildDefaultMergedContextConfiguration(AbstractTestContextBootstrapper.java:323)
Run Code Online (Sandbox Code Playgroud)
这是我的 RentalCarSystemApplicationTests.java
package com.test.project.rentalcarsystem;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class RentalCarSystemApplicationTests {
@Test
public void contextLoads()
{
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 TestWebApp.java
package com.test.project.rentalcarsystem;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.springframework.web.context.WebApplicationContext;
import org.junit.Before;
import …
Run Code Online (Sandbox Code Playgroud) 发生异常时如何显示相应的错误信息。
假设在 GET 方法期间,如果未找到数据,则应显示自定义异常消息。
同样,如果我们试图删除不可用的数据。
Car.java
package com.car_rental_project.car_project;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Car {
@Id
private String id;
private String modelname;
private String type;
private String year_of_registration;
private String seating_capacity;
private String cost_per_day;
private String milleage;
private String pincode;
private String contact_number;
private String email;
public Car() {
}
public Car(String id, String modelname, String type, String year_of_registration, String seating_capacity,String cost_per_day, String milleage, String pincode, String contact_number, String email) {
super();
this.id = id;
this.modelname = modelname; …
Run Code Online (Sandbox Code Playgroud) 如何使用 PrimeNG 执行 On-click 事件。
当我们单击 New 菜单栏以获取 UserFormComponent.html 页面以添加新用户时。使用 PrimeNG 我们如何执行此操作。
我的代码可在:https: //stackblitz.com/edit/angular-rlf3nz appcomponent.html
<p-menubar [model]="items">
Run Code Online (Sandbox Code Playgroud)
应用组件.ts
export class AppComponent {
private user = new User(); //Newly added
constructor(private _userService:UserService) { } //Newly added
title = 'clientApp';
private items: MenuItem[];
ngOnInit() {
this.items = [
{
label: 'Quotes',
items: [
{ label: 'New ', icon: 'fa fa-refresh', command: () => this.addNewUser()},
{ label: 'Show All', icon: 'fa fa-repeat', url: '#' }
]
}
addNewUser(){
this.user=this._userService.getter();
}
Run Code Online (Sandbox Code Playgroud)
}
这是我的 …