21
www.querity.cz TEST NG & JPA VALIDATION Ing. Jiří Kiml, 26/02/2015, Bern

TestNG & JPA Validation

Embed Size (px)

Citation preview

www.querity.cz

TEST NG & JPA VALIDATION

Ing. Jiří Kiml,26/02/2015, Bern

www.querity.cz

Agenda

►Motivation

►JPA validation

►TestNG vers. JUnit

►Summary

►Questions

www.querity.cz

Motivation

Kill two birds with one stone.Light two candles with one flame.Smell two flowers with one nose. Tickle two bugs with one hug.

►I like TestNG

►WET (NOT DRY) validation code

►Deeper look at topic

www.querity.cz

Agenda

►Motivation

►JPA validation

►TestNG vers. JUnit

►Best practices

►Summary

►Questions

www.querity.cz

JPA validation

►Validating Persistent Fields

►Persistence provider will automatically perform validation on entities immediately after the PrePersist, PreUpdate, and PreRemove lifecycle events.

►Built-in constraints in the javax.validation.constraints package

►User-defined constraints

►Which column is too long?

Caused by: org.hsqldb.HsqlException: data exception: string data, right truncation

www.querity.cz

Agenda

►Motivation

►JPA validation

►TestNG vers. JUnit

►Best practices

►Summary

►Questions

www.querity.cz

Test NG

►Testing framework

►Written by Cédric Beust

►New functionalities over Junit

►More powerful and easier to use

http://www.testng.org

www.querity.cz

TestNG overview

►@Before.../@After...►Exception Tests►Groups►@DataProvider ►Dependency Test

www.querity.cz

Annotations►Junit @BeforeClass and @AfterClass

methods have to be declared as static

►TestNG: @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, @BeforeGroup and @AfterGroup

www.querity.cz

Exception Tests►Junit:@Test(expected =

ConstraintViolationException.class)

►TestNG:@Test(expectedExceptions =

ConstraintViolationException.class, expectedExceptionsMessageRegExp = "...")

www.querity.cz

Parametrized tests►Junit@RunWith(value = Parameterized.class)

►TestNG@Test(dataProvider = "correctData")

www.querity.cz

Groups►Junit@Category(FastTest.class)Category annotations on Parameterized

classes are not supported on individual methods.

►TestNG@Test(groups = "fast")

www.querity.cz

Dependency Test►JunitNo support, independent tests only►TestNG@Test(dependsOnMethods = "testXXX")

www.querity.cz

Agenda

►Motivation

►JPA validation

►TestNG vers. JUnit

►Best practices

►Summary

►Questions

www.querity.cz

Best Practices►?? Use JPA validation► ?? Every String field annotated by

@Column annotation should have length and also @Size annotation ??

►Write (junit) tests ExtensivelyTest framework is NOT so important.

www.querity.cz

Agenda

►Motivation

►JPA validation

►TestNG vers. JUnit

►Best practices

►Summary

►Questions

www.querity.cz

Summary – what we use?

►Junit and TestNG features more or less equivalent

►TestNG is slightly more powerful and elegant

►JPA validation ?

www.querity.cz

Agenda

►Motivation

►JPA validation

►TestNG vers. JUnit

►Best practices

►Summary

►Questions

www.querity.cz

Questions … … and maybe answers

@RunWith(DataProviderRunner.class)

www.querity.cz

Links

http://http://www.testng.org/

https://http://junit.org/

http://http://www.mkyong.com/unittest/junit-4-vs-testng-comparison/

http://http://docs.oracle.com/javaee/6/tutorial/doc/gircz.html

https://github.com/TNG/junit-dataprovider/wiki/Getting-started

www.querity.cz

Thank you

Ing. Jiří Kiml ,26/02/2015, Bern