我正在开发微服务应用程序,我需要测试对控制器的发布请求。手动测试有效,但是测试用例始终返回null。
我已经在Stackoverflow和文档中阅读了许多类似的问题,但是还没有弄清楚我所缺少的东西。
这是我目前拥有的以及为了使其工作而尝试的方法:
//Profile controller method need to be tested
@RequestMapping(path = "/", method = RequestMethod.POST)
public ResponseEntity<Profile> createProfile(@Valid @RequestBody User user, UriComponentsBuilder ucBuilder) {
Profile createdProfile = profileService.create(user); // line that returns null in the test
if (createdProfile == null) {
System.out.println("Profile already exist");
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
HttpHeaders headers = new HttpHeaders();
headers.setLocation(ucBuilder.path("/{name}").buildAndExpand(createdProfile.getName()).toUri());
return new ResponseEntity<>(createdProfile , headers, HttpStatus.CREATED);
}
//ProfileService create function that returns null in the test case
public Profile create(User user) {
Profile existing = …Run Code Online (Sandbox Code Playgroud) 我是python的新手,我正在尝试创建一个csv解析脚本.我将行从csv传递到列表,但目前我遇到的麻烦是我需要在每个项目中添加第一个标题行作为字典.
def parse_csv(datafile):
data = []
with open(datafile, "r") as f:
next(f) #skip headerline
for line in f:
splitLine = line.strip(',')
rowL = splitLine.rstrip('\n') #remove the newline char
data.append(rowL)
pprint(data)
return data
Run Code Online (Sandbox Code Playgroud)
如果第一个标题行有字典(例如标题,名称等),我将如何传递给每个被剥离的元素?
例如{'Dict1':'data1','Dict2':'data2'}
这可能被视为重复,但从类似的帖子尝试了各种方式,但没有在我的情况下正常工作.