Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arnzel/mockMvcTestCreator
Library to generate Unit-Tests using mockMvc for Spring Controller Classes
https://github.com/arnzel/mockMvcTestCreator
generator java junit spring-mvc test-automation testing
Last synced: 3 months ago
JSON representation
Library to generate Unit-Tests using mockMvc for Spring Controller Classes
- Host: GitHub
- URL: https://github.com/arnzel/mockMvcTestCreator
- Owner: arnzel
- Created: 2020-02-17T08:13:36.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-16T15:30:48.000Z (about 2 years ago)
- Last Synced: 2023-05-12T21:45:40.868Z (over 1 year ago)
- Topics: generator, java, junit, spring-mvc, test-automation, testing
- Language: Java
- Homepage:
- Size: 49.8 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mockMvcTestCreator
![Build Status](https://travis-ci.com/arnzel/mockMvcTestCreator.svg?branch=master)
Generates Tests for Spring Mvc Controller
Example Controller Class
```
package fixtures.controllers;import static org.springframework.web.bind.annotation.RequestMethod.GET;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class MethodMappingController {@RequestMapping(value="/controller", method=GET)
public String getMapping() {
return "GetMapping";
}
}
```Generated Test
```
package fixtures.controllers;import java.lang.Exception;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;class MethodMappingControllerTest {
private final MockMvc mockMvc;private final MethodMappingController methodMappingController;
public MethodMappingControllerTest() {
this.methodMappingController = new MethodMappingController();
this.mockMvc = MockMvcBuilders.standaloneSetup(new MethodMappingController()).build();
}@Test
public void getMapping() throws Exception {
mockMvc.perform( MockMvcRequestBuilders.get("/controller").accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultHandlers.print());
}
}```