Beruflich Dokumente
Kultur Dokumente
BPMWAVE
JUnit 4
JUnit is the most popular java unit testing framework along with TestNG
Advantages and functionalities
adnotations
assertions
test suits
parametrizations
rules
categories
visual reprezentation
works with many additional libraries( ex: Mockito,Arquillian,Selenium )
BPMWAVE
Common annotations
@Test
public void method()
@Before
public void method()
@BeforeClass
public static void method()
@After
public void method()
@AfterClass
public static void method()
@Ignore
public static void method()
Assertions
Assertion
Description
BPMWAVE
Test suits
Insoftwaredevelopment,atestsuite,lesscommonlyknownasavalidation suite,
isacollectionoftestcasesthatareintendedtobeusedtotestasoftware
programtoshowthatithassomespecifiedsetofbehaviours.Atestsuiteoften
containsdetailedinstructionsorgoalsforeachcollectionoftestcasesand
informationonthesystemconfigurationtobeusedduringtesting.Agroupoftest
casesmayalsocontainprerequisitestatesorsteps,anddescriptionsofthe
followingtests.
BPMWAVE
Parameterized JUnit
Parameterizedunittestsareusedtotestthesamecodeunderdifferent
conditions.Thankstoparameterizedunittestswecansetupatestmethodthat
retrievesdatafromsomedatasource.Thisdatasourcecanbeacollectionof
testdataobjects,externalfileormaybeevenadatabase.Thegeneralideaisto
makeiteasytotestdifferentconditionswiththesameunittestmethod,which
willlimitthesourcecodeweneedtowriteandmakesthetestcodemore
robust.Wecancallthesetestsdata-drivenunittests.
BPMWAVE
BPMWAVE
Rules
Rules add special handling around tests, test cases or test suites.
They can do additional validations common for all tests in the class,
concurrently run multiple test instances, set up resources before each
test or test case and tear them down afterwards.
The rule gets complete control over what will done with the test
method, test case or test suite it is applied to. Complete control
means that the rule decides what to do before and after running it
and how to deal with thrown exceptions.
BPMWAVE
BPMWAVE
Categories
Categories are used to organize tests. For example, we can use them
to easily distinguish performance unit test from integration tests or
slow tests from faster tests.
BPMWAVE
BPMWAVE
Mockito example
BPMWAVE
To create a mock of a class you simply call the static method mock,
or you can also use adnotations (@Mock). Using static methods
when and thenReturns you can tell the mocked class how to
behave.
BPMWAVE
BPMWAVE
BPMWAVE
Intrebari ?
?
??
?
?
?
?
BPMWAVE