Weitere ähnliche Inhalte Ähnlich wie Testdrevet javautvikling på objektorienterte skinner Ähnlich wie Testdrevet javautvikling på objektorienterte skinner (20) Mehr von Truls Jørgensen (12) Kürzlich hochgeladen (20) Testdrevet javautvikling på objektorienterte skinner12. rask oppstart
kjapp feedback
mindre kompleksitet
lett å integrere med tester
24. @Test
public skalTesteGodkjenning() {
PersonRepository personRepo =
mock(PersonRepository.class);
when(personRepo)
.getPerson(any(Long))
.returnValue(TestDataProvider
.standardPerson().build());
}
25. @Test
public skalTesteGodkjenning() {
PersonRepository personRepo =
mock(PersonRepository.class);
when(personRepo)
.getPerson(any(Long))
.returnValue(TestDataProvider
.standardPerson().build());
SoknadService service =
new SoknadServiceImpl(personRepo);
Soknad soknad = TestDataProvider
.standardSoknad()
.status(GODKJENT).build();
}
26. @Test
public skalTesteGodkjenning() {
PersonRepository personRepo =
mock(PersonRepository.class);
when(personRepo)
.getPerson(any(Long))
.returnValue(TestDataProvider
.standardPerson().build());
SoknadService service =
new SoknadServiceImpl(personRepo);
Soknad soknad = TestDataProvider
.standardSoknad()
.status(GODKJENT).build();
assertFalse(service.godkjennSoknad(soknad));
}
28. public class OrganizationNumber {
@NotBlank
@Digits(integer=9, fraction=0)
@Min(value=100000000)
@ValidOrganizationNumber
private String value;
}
@Valid
private OrganizationNumber organizationNumber;
29. public class OrganizationNumber {
@NotBlank
@Digits(integer=9, fraction=0)
@Min(value=100000000)
@ValidOrganizationNumber
private String value;
}
@Valid
@NotNull(groups=GodkjennSoknadContext.class)
private OrganizationNumber organizationNumber;
35. Organization org =
OrganizationTestDataProvider
.defaultOrganization()
.name(”¤Invalid")
.build();
36. Organization org =
OrganizationTestDataProvider
.defaultOrganization()
.withoutEmployees()
.build();
37. Organization org =
OrganizationTestDataProvider
.defaultOrganization ()
.withoutEmployees()
.build(entityManager);
41. @RequestMapping(method = RequestMethod.POST)
public String registerRequestInformation(
@Valid @ModelAttribute
InformationRequest informationRequest,
Errors errors) {
if (errors.hasErrors()) {
return VIEW_INFORMATION_REQUEST_FORM;
}
this.orgRepo
.addInformationRequest(informationRequest);
}
42. @RequestMapping(method = RequestMethod.POST)
public String registerRequestInformation(
@Valid @ModelAttribute
InformationRequest informationRequest,
Errors errors) {
if (errors.hasErrors()) {
return VIEW_INFORMATION_REQUEST_FORM;
}
this.orgRepo
.addInformationRequest(informationRequest);
return redirectTo(URL_INFORMATION_REQUEST);
}
43. @RequestMapping(method = RequestMethod.GET,
value = ”ir/{requestId}/received”)
public String registerRequestAsReceived(
@PathVariable Long requestId ) {
InformationRequest informationRequest =
this.orgRepo
.getInformationRequest( requestId );
informationRequest.received();
return redirectTo(
url("/", URL_INFORMATION_REQUEST));
}
44. @RequestMapping(method = RequestMethod.GET,
value = ”ir/{requestId}/received”)
public @ResponseBody InformationRequest
registerRequestAsReceived(
@PathVariable Long requestId) {
InformationRequest informationRequest =
this.orgRepo
.getInformationRequest(requestId);
return informationRequest;
}
47. Testdata builders http://nat.truemesh.com/archives/000714.html
Object mother http://martinfowler.com/bliki/ObjectMother.html
Jetty embedded http://docs.codehaus.org/display/JETTY/Embedding+Jetty
JSR 303 http://jcp.org/en/jsr/detail?id=303
Spring MVC http://static.springsource.org/spring/docs/3.0.x/spring-
framework-reference/html/mvc.html
Hinweis der Redaktion A A -> T T T T T A T T Eiappserveren A A & T A T A T A T T A A T T A A A A T T A AVis app med 2 forhåndsinnlagterequestsSteng den eneVis kjøring av tester (påpek Jetty)Endre controllerVis kjøring med plugin (JUnitMax og Infinitest)Vis applikasjon med å legge innVis at close ikke fungererFiks closeKjør grønt T T T T T T -> A A A A A T A A & T T A