• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Testdrevet javautvikling på objektorienterte skinner
 

Testdrevet javautvikling på objektorienterte skinner

on

  • 708 views

 

Statistics

Views

Total Views
708
Views on SlideShare
705
Embed Views
3

Actions

Likes
1
Downloads
5
Comments
0

1 Embed 3

http://www.linkedin.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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

Testdrevet javautvikling på objektorienterte skinner Testdrevet javautvikling på objektorienterte skinner Presentation Transcript

  • testdrevet javautviklingpå objektorienterte skinner Anders Sveen og Truls Jørgensen JavaZoneX
  • Java er ikke morsomt eller sexy
  • Java7 er ikke morsomt eller sexy
  • hva du gjør er viktigere
  • rask oppstart kjapp feedback mindre kompleksitetlett å integrere med tester
  • lite påtrengende enkelt å utvideenkelt å gå rundt open source
  • en følelse av å væreproduktiv
  • enkelt å legge til nye features
  • endringsdyktigobjektorientert kode
  • isolasjonansvarsdeling
  • if (soknad.getStatus().equals(VENTER)) { soknad.setGodkjentDato(new Date()); soknad.setStatus(GODKJENT);} VSif (soknad.kanGodkjennes()) { soknad.godkjenn();}
  • @Testpublic skalTesteGodkjenning() {}
  • @Testpublic skalTesteGodkjenning() { PersonRepository personRepo = mock(PersonRepository.class); when(personRepo) .getPerson(any(Long)) .returnValue(TestDataProvider .standardPerson().build());}
  • @Testpublic 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();}
  • @Testpublic 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));}
  • @Testpublic void skalTesteGodkjenning() { Soknad soknad = TestDataProvider .standardSoknad() .godkjent().build(); assertFalse(soknad.kanGodkjennes());}
  • public class OrganizationNumber { @NotBlank @Digits(integer=9, fraction=0) @Min(value=100000000) @ValidOrganizationNumber private String value;}@Validprivate OrganizationNumber organizationNumber;
  • public class OrganizationNumber { @NotBlank @Digits(integer=9, fraction=0) @Min(value=100000000) @ValidOrganizationNumber private String value;}@Valid@NotNull(groups=GodkjennSoknadContext.class)private OrganizationNumber organizationNumber;
  • @RequestMapping(method =RequestMethod.POST)public String registerOrganization( @Valid @ModelAttribute Organization organization, Errors errors) { ...}
  • trygghet til å gjøre endringer
  • lettå skrive tester
  • Organization org = OrganizationTestDataProvider .defaultOrganization();
  • Organization org = OrganizationTestDataProvider .defaultOrganization() .name(”¤Invalid") .build();
  • Organization org = OrganizationTestDataProvider .defaultOrganization() .withoutEmployees() .build();
  • Organization org = OrganizationTestDataProvider .defaultOrganization () .withoutEmployees() .build(entityManager);
  • @RequestMapping(method = RequestMethod.POST)public String registerRequestInformation( @Valid @ModelAttribute InformationRequest informationRequest, Errors errors) {}
  • @RequestMapping(method = RequestMethod.POST)public String registerRequestInformation( @Valid @ModelAttribute InformationRequest informationRequest, Errors errors) { this.orgRepo .addInformationRequest(informationRequest);}
  • @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);}
  • @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);}
  • @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));}
  • @RequestMapping(method = RequestMethod.GET, value = ”ir/{requestId}/received”)public @ResponseBody InformationRequest registerRequestAsReceived( @PathVariable Long requestId) { InformationRequest informationRequest = this.orgRepo .getInformationRequest(requestId); return informationRequest;}
  • oppsummert:
  • github.com/anderssv/jzx-weboo
  • Testdata builders http://nat.truemesh.com/archives/000714.htmlObject mother http://martinfowler.com/bliki/ObjectMother.htmlJetty embedded http://docs.codehaus.org/display/JETTY/Embedding+JettyJSR 303 http://jcp.org/en/jsr/detail?id=303Spring MVC http://static.springsource.org/spring/docs/3.0.x/spring- framework-reference/html/mvc.html
  • 14.-15. novemberRadisson Blu Plaza, Oslohttp://smidig2011.no