Index [ptgmedia.pearsoncmg.com] · Complex classes, mocks and stubs for, 99–100 Complexity...
Transcript of Index [ptgmedia.pearsoncmg.com] · Complex classes, mocks and stubs for, 99–100 Complexity...
471
Index
Abbot framework, 312–317AbbotFixture class, 314–315Absolute performance testing, 86AbstractAnnotationAwareTransactionalTests class,
278–279AbstractDependencyInjectionSpringContext-
Tests class, 244, 274–275AbstractSingleSpringContextTests class, 273AbstractSpringContextTests class, 272–273AbstractTransactionalDataSourceSpringContext-
Tests class, 278AbstractTransactionalSpringContextTests class,
238, 244, 276–278AbstractWSTest class, 249activeAfter attribute, 367–371ActiveMQ message broker, 221
downloading and installing, 221–222running, 222–223state handling, 223–225
@AfterClass annotation, 20, 170, 424AfterClassCalledAtEnd test, 356@AfterGroups annotation, 20, 424@AfterMethod annotation, 20, 424@AfterSuite annotation, 20, 170, 424@AfterTest annotation, 20, 424Algorithm complexity, 84–87AllTests pattern, 463–467alwaysRun attribute, 425, 427-annotation option in JUnitConverter, 450Annotation transformers, 346
annotation history, 346–347pros and cons, 348usage, 353–355working with, 348–353
Annotationscustom, 366–367
implementation, 367–371testing, 371–375
inheritance, 113–116
IntelliJ IDEA, 419Javadocs, 423–428JDK 1.4 and JDK 5, 421–423scopes, 113–119TestNG framework, 17–20
annotations attribute<suite>, 438<test>, 445
AnnotationServiceFactory class, 250AnnotationTransformerClassSampleTest class,
328ant task
JUnitConverter from, 452–453for running groups, 126
Anthill, 321Assert class, 457assert functions, 457Assertions, 265, 457–458AssertJUnit class, 457Asynchronous testing, 67–71Atomikos TransactionEssentials transaction
manager, 218Attributes
ant, 126, 452–453encapsulated, 36factories, 35–36Javadocs, 421–422<package>, 441<parameter>, 441–442<selector-class>, 443<suite>, 437–440<suite-file>, 442<test>, 444–445
Bamboo, 321Base classes
dependencies, 116–118JUnit tests, 4
Bean Scripting Framework (BSF), 337
Beust.book Page 471 Monday, September 17, 2007 12:36 PM
472 Index
BeanShell language, 335interactive execution, 339–341overview, 335–337with TestNG, 337–339
@BeforeClass annotation, 20, 69, 111–112, 424@BeforeGroups annotation, 20, 112, 424@BeforeMethod annotation, 20, 111–112, 424@BeforeSuite annotation, 20, 112, 424@BeforeTest annotation, 20, 112, 424Big O notation, 84–87Binary code coverage implementation, 146Block coverage, 135–136Bootstrapping in JNDI, 207–209Branch coverage, 136Broken tests, 127–129BSF (Bean Scripting Framework), 337Bugs, debuggers for, 392–394Build tool integration in code coverage, 137build.xml template, 12, 137–138
for Clover, 139for converting JUnit, 452–453for EMMA, 142groups in, 126parsing, 322
Builds, CI server, 321
c3p0 library, 212–213Caching Spring containers, 271, 273, 279Callback methods in asynchronous testing, 68–69Cascade failures, 103Categories, test group, 129–131Check-in tests, 130Checked exceptions
avoiding, 381design patterns, 25–27
CI (continuous integration), 320benefits, 320servers, 320–321TestNG, 321–322
Class coverage, 135<class> tag, 331, 446–447Class-wide initialization, 463Classes
dependencies, 116–118Eclipse for, 405IntelliJ IDEA tests, 415–416JUnit tests, 3–4mocks and stubs, 99–100
<classes> tag, 446
Classloaders in code coverage, 146ClassScanner class, 201–202CLEAN_INSERT operation, 298–299Clients
embedded containers, 258–259JAX-WS, 246
clover-setup task, 140Clover tool, 138–141Cobertura tool, 144–146Code conversion. See JUnit migrationCode coverage, 132–133
Clover tool, 138–141Cobertura tool, 144–146design for, 149difficulties, 148EMMA tool, 142–144example, 133–134guidelines, 147–148history, 150implementation, 146–147importance, 149limitations, 147, 149–150metrics, 134–136percentages, 148–149reports, 137, 148tools, 136–138
CollectingAlertHandler class, 309ComboPooledDataSource class, 213Command line
JUnitConverter, 449–452running groups from, 125–126
Commons DBCP library, 213Competing Consumers pattern, 182–186Compiling with Clover, 140Complex classes, mocks and stubs for, 99–100Complexity
algorithm, 84–87mocks, 102
Component Injection, 210ComponentDataProvider class, 180–181ComponentFunctionalTests class, 179–180ComponentTester interface, 316ComponentUnitTests class, 180concurrent package, 67–68Concurrent running, 79–82Concurrent testing, 72–78Configuration
ActiveMQ, 223DbUnit, 295–297
Beust.book Page 472 Monday, September 17, 2007 12:36 PM
Index 473
dependencies in, 110–112Eclipse, 404–410Guice, 286–290, 293–295HtmlUnit, 304–305JUnit tests, 6logging, 396Swing UI, 313–314
Connection interface, 168–170Connections
JDBC, 211transaction rollbacks, 168–170
ContainersEJB3, 243–246Java EE testing. See In-container testingJPA simulation, 230–236servlets, 257–260
Continuous integration (CI), 320benefits, 320servers, 320–321TestNG, 321–322
Continuum product, 321Contract capture, mocks and stubs for, 100Conversions, code. See JUnit migrationCreditCardTest class, 113–114.csv files, 63–65Custom annotations, 366–367
implementation, 367–371testing, 371–375
CvsReader class, 66
-d option for JUnitConverter, 450Dashboard
CI servers, 321Clover, 141
Data Access Object (DAO), 282Data Access Object (DAO) pattern, 90Data-Driven Testing
Data Providers. See Data Providersdesign patterns, 39–42enterprise, 164, 173parameters and test methods, 42–50
Data Providers, 47–50Competing Consumers pattern, 185data for, 60–62enterprise testing, 164–165vs. factories, 62–63ITestContext parameters for, 52–54lazy, 54–59
Method parameters for, 50–52summary, 63–67vs. testng.xml, 59–60
Data size in algorithm complexity, 84–85Databases
enterprise testing, 166–167JPA, 227
@DataProvider annotationdefault reports, 356enterprise testing, 165overview, 425–426passing parameters with, 47–60
dataProvider attributeannotation transformers, 354@Test, 427
dataProviderClass attributeannotation transformers, 354@Test, 427
DataSource classc3p0 library for, 212–213transaction rollbacks, 168
DBTestCase example, 299–301DBTests class, 302–303DbUnit, 211
configuration, 295–297features, 295usage, 297–299verifying results, 299–303
DBUnitTests class, 299–300Debuggers, 392–394Decision coverage, 136Decorator pattern, 170Decoupling in enterprise testing, 162Default reports, 355–358<define> tag, 446Delegate pattern, 178Delegation, 8Dependencies
CI servers, 321enterprise testing, 177Guice, 282–284, 291–293JUnit tests, 6–7logging, 396
Dependency Injection pattern, 13EJB3, 236and JNDI, 190, 210Spring framework, 271–272
Dependency stubs, 246
Beust.book Page 473 Monday, September 17, 2007 12:36 PM
474 Index
Dependent testing, 103–104dependent code, 104–105groups vs. methods, 106–110with TestNG, 105–106and threads, 110–112
dependsOnGroups attribute, 106, 425annotation transformers, 355vs. dependsOnMethods, 106–110@Test, 109–110, 427
dependsOnMethods attribute, 112, 425Competing Consumers pattern, 185vs. dependsOnGroups, 106–110@Test, 427
Deprecated annotations, 419Derby database, 227description attribute, 425
annotation transformers, 354@Test, 427
Design for code coverage, 149Design for testability, 8
design patterns, 9–10extreme encapsulation, 14–16object-oriented programming and
encapsulation, 8–9problems, 10–11recommendations, 16static methods and fields, 11–14
Design patterns, 9–10asynchronous testing, 67–71code coverage. See Code coverageData-Driven Testing. See Data-Driven Testingdependent testing. See Dependent testingfactories, 34–39inheritance and annotation scopes, 113–119mocks and stubs. See Mock objects; Stub
objectsmultithreaded code, 71–72
concurrent running, 79–82concurrent testing, 72–78parallel bit, 82–83
performance testing, 83–89test groups. See Test groupstesting for failures. See Failure testing
Destinations in Competing Consumers pattern, 182@DirtiesContext annotation, 279DOM API, 253dom4j API, 263–264
Don’t Repeat Yourself (DRY) principle, 30, 113, 164Driver class, 168DriverManager class, 211–212, 214DRY (Don’t Repeat Yourself) principle, 30, 113, 164
EasyMock library, 96–99, 102Eclipse plug-in, 401
installing, 401–404JUnit migration, 453JUnit test conversions, 410–411launch configuration, 404–409preferences, 410
EE testing. See Java EE testingEJB entity beans (JPA), 210EJB3. See Enterprise Java Beans 3.0 (EJB3)EJBGen tool, 347Email notifications, 321EmailableReporter reporter, 204–205Embedded containers for servlets, 257–260Embedded databases in enterprise testing,
166–167EMMA tool, 142–144enabled attribute, 425
annotation transformers, 353@Test, 427
Encapsulated attributes, 36Encapsulation, 8–9
extreme, 14–16vs. testing, 391–392
Enterprise Java Beans 3.0 (EJB3), 236–237full containers, 244–246Message-Driven Beans, 237–239Session beans, 240–243Spring containers, 243–244
Enterprise testing, 153–154Competing Consumers pattern, 182–186current approach, 156–157error handling, 172–175example, 157–160implementation, 160–161, 178–181in-container components, 177–178, 193refactoring, 186–193scenario, 154–157setup issues, 166–171for success, 161–163test data for, 163–165unit tests, 175–177
Beust.book Page 474 Monday, September 17, 2007 12:36 PM
Index 475
EntityManager class, 230EntityManagerFactory class, 230Error handling, 172–175Error reporting, 24–25Exception class, 25Exceptions,
design patterns, 25–27JUnit migration, 467–468JUnit tests, 4–5overview, 378–382
exclude attribute, 441Exclusion in code coverage, 137ExpectedAttribute class, 36@ExpectedException annotation, 278expectedExceptions attribute, 28–32, 427External APIs for mocks, 101Extreme encapsulation, 14–16Extreme Programming, 385, 397
Factoriesvs. Data Providers, 62–63design patterns, 34–39
@Factory annotation, 35–38, 426FadedIcon class, 317FailedReporter reporter, 204Failure testing, 23–24
error handling, 27–31error reporting, 24–25exceptions, 25–27expectedExceptions, 31–32testng-failed.xml, 32–34
File filters, Java EE testing, 203Filters
ActiveMQ, 224Java EE testing, 203Servlet, 193
final scope, 392Flickr application, 120Functional tests, 154
Gamma, Erich, 2, 9Gang of Four, 9Global logging, 396Gmail application, 120Goals
enterprise testing, 159–160mocks and stubs, 100
Graphics code, 316–320Green bars in code coverage, 147Groups
in dependent testing, 106–110Eclipse for, 406Guice test dependencies, 291–293IntelliJ IDEA tests, 415test. See Test groupsTestNG framework, 20–21
groups attribute, 425annotation transformers, 355@Test, 120–121, 427
-groups option in JUnitConverter, 450<groups> tag, 446groups variable, 339Guice, 280
benefits, 280–282configuration, 286–290dependencies, 291–293dependency scenario, 282–284injecting configuration, 293–295object factory, 284–286tests, 290–291
GuiceModuleObjectFactory class, 291–292GuiceObjectFactory class, 289Helm, Richard, 9Hibernate tool, 210, 225, 234Hierarchies, mock object, 102Historical coverage tracking, 137History
annotation, 346–347code coverage, 150
Hooks, 15HtmlUnit, 303–304
complex example, 308–310configuration, 304–305usage, 305–308
HTTP requests, 261HttpTester class, 262Hudson product, 321–322IAnnotationTransformer interface, 349Idempotent tests, 166IDEs (Integrated Development Environments)
code coverage, 136–137Eclipse. See Eclipse plug-inIntelliJ IDEA. See IntelliJ IDEA plug-in
IMethodSelector interface, 341, 346
Beust.book Page 475 Monday, September 17, 2007 12:36 PM
476 Index
Immutable state, 382–383In-container testing
enterprise, 177–178, 193Java EE, 200
identifying tests, 201–203registering results listeners, 204–206registering tests, 203–204test environment, 200–201
servlets, 255In-memory invocation, 260–262include attribute, 441Incremental JUnit migration, 455–456Information hiding, exceptions from, 380Inheritance
annotation, 113–116pitfalls, 116–119
inheritGroups attribute, 425InitialContext class, 207–209, 212InitialContextFactory class, 208Initialization
in enterprise test setup, 167–168with extreme encapsulation, 14–16JUnit, 463lazy, 55–56
InitializationStrategy class, 16@Inject annotation, 289Injection
dependency. See Dependency Injection pat-tern
Guice, 293–295Message-Driven Beans, 239resource, 230–231
Injector class, 287–288Inline setup example, 301–303Inspecting variables, 393Instrumenting classes in EMMA, 142–143Integrated Development Environments (IDEs)
code coverage, 136–137Eclipse. See Eclipse plug-inIntelliJ IDEA. See IntelliJ IDEA plug-in
Integration, 154, 269–270continuous, 320–322DbUnit
configuration, 295–297features, 295usage, 297–299verifying results, 299–303
enterprise testing, 157Guice. See Guice
HtmlUnit, 303–304complex example, 308–310configuration, 304–305usage, 305–308
painting code, 316–320Selenium, 310–311Spring framework. See Spring frameworkSwing UI testing, 312–316
IntelliJ IDEA plug-in, 411installing, 411–412JUnit migration, 454–455refactorings, 419running tests, 412–419
Interactive execution in BeanShell, 339–341Interfaces for mocks and stubs, 99Invalid data in enterprise testing, 173–175Inversion of Control (IoC) technique, 13
benefits, 270container, 96, 210
invocationCount attribute, 278annotation transformers, 354Competing Consumers pattern, 185–186multithreaded code, 73, 75–76@Test, 427
InvocationTransformer class, 351IObjectFactory interface, 284IoC (Inversion of Control) technique, 13
benefits, 270container, 96, 210
IReporter interface, 364–366Isolation levels for rollbacks, 168Iterator interface, 55–56, 64–65ITest interface, 38–39, 349–350, 360ITestContext parameter, 52–54ITestListener interface, 326, 361–366ITestNGMethod interface, 327ITestResult interface, 327
Java API for XML Web Services (JAX-WS), 246–247
recording requests, 248remote services tests, 254–255service test, 251–253test environment, 248–251XPath testing, 253–254
Java Database Connectivity (JDBC), 210–212c3p0 library, 212–213Commons DBCP library, 213Spring framework, 213–214
Beust.book Page 476 Monday, September 17, 2007 12:36 PM
Index 477
Java EE testing, 197–198EJB3. See Enterprise Java Beans 3.0 (EJB3)in-container. See In-container testingJAX-WS. See Java API for XML Web Services
(JAX-WS)JDBC, 210–214JMS, 219
ActiveMQ for, 221–225sender/receiver tests, 219–221
JNDI. See Java Naming and Directory Interface (JNDI)
JPA. See Java Persistence API (JPA)JTA, 215–218servlets. See ServletsXML, 262–266
Java Messaging Service (JMS), 219ActiveMQ for, 221–225sender/receiver tests, 219–221
Java Naming and Directory Interface (JNDI), 207avoiding, 210bootstrapping, 207–209JMS in, 220–221in JTA, 216Spring setup, 209–210
Java Open Transaction Manager (JOTM), 217Java Persistence API (JPA), 210, 225–227
container simulation, 230–236database, 227providers, 227–229writing tests, 229–230
Java Transaction API (JTA), 215–218, 228JavaDB, 227-javadoc option for JUnitConverter, 450–451Javadocs, 421
annotations, 106, 423–428JDK 1.4 and JDK 5, 421–423TestNG class, 428–432XML API, 432–433
JAX-WS. See Java API for XML Web Services (JAX-WS)
JDBC (Java Database Connectivity), 210–212c3p0 library, 212–213Commons DBCP library, 213Spring framework, 213–214
JdbcBasedDBTestCase class, 299JDK 1.4 and JDK 5 support, 421–423JDOM API, 253Jetty container, 257–258, 260
jMock library, 96, 98–99, 102JMS (Java Messaging Service), 219
ActiveMQ for, 221–225sender/receiver tests, 219–221
JMSMessage class, 161JNDI (Java Naming and Directory Interface), 207
avoiding, 210bootstrapping, 207–209JMS in, 220–221in JTA, 216Spring setup, 209–210
JOTM (Java Open Transaction Manager), 217JPA (Java Persistence API), 210, 225–227
container simulation, 230–236database, 227providers, 227–229writing tests, 229–230
JpaTransactionManager class, 234JTA (Java Transaction API), 215–218, 228junit attribute, 445JUnit migration, 449
code conversion, 456–457AllTests pattern, 463–467assertions, 457–458class-wide initialization, 463parameterized test case pattern, 469single tests, 458–461state maintenance, 461–462suite-wide initialization, 463testing exceptions, 467–468
Eclipse, 453incremental, 455–456IntelliJ IDEA, 419, 454–455JUnitConverter, 449–453
JUnit mode, 455–456JUnit tests, 1–2
base classes, 4configuration methods, 6converting, 410–411dependencies, 6–7exceptions, 4–5JUnit 3 tests, 42–43JUnit 4 tests, 7parameters, 4real-world testing, 6running, 5stateful classes, 3–4summary, 7
Beust.book Page 477 Monday, September 17, 2007 12:36 PM
478 Index
JUnitConverter tool, 449from ant, 452–453command line, 449–452
JUnitReport plug-in, 361JUnitTest class, 450–452, 461–462
language attribute, 444Launch configuration in Eclipse, 404–409Lazy Data Providers, 54–59Lazy initialization, 55–56Libraries
c3p0, 212–213mock, 93–94, 96–99Xerces, 380–381
Lifecycle methods in Session beans, 242–243Listeners
registering, 204–206reports, 361–366
LoadTransformer class, 350Log and rethrow exception handling, 380Logging best practices, 394–397LoggingObjectFactory class, 285login servlet testing, 187–193LoginController class, 390LoginManager class, 189–192Luntbuild product, 321
Mailer interface, 90–92, 282MailerStub class, 92Maintenance overhead for mocks, 102Manual rollbacks, 168Manual setup in EJB3, 246MapSession class, 249Merging instrumentation data in EMMA, 142Message-Driven Beans (MDBs), 177–178,
237–239MessageContext class, 251MessageHandler class, 237–239MessageHandlerTests class, 238MessageProcessor class, 183Messages
ActiveMQ, 224Competing Consumers pattern, 182–183
Method parameters for Data Providers, 50–52<method-selector> tag, 331, 443<method-selectors> tag, 443method variable, 339Methodology for enterprise testing, 155–156
MethodsBeanShell, 336callback, 68–69coverage, 135dependent testing, 106–110Eclipse for, 407IntelliJ IDEA tests, 416private, 388–391scope, 391–392selectors, 341–346
<methods> tag, 447MethodSelector class, 343Metrics for code coverage, 134–136Microdesign, 385–386Migration, JUnit. See JUnit migrationMock objects, 90
designing for, 95–96enterprise testing, 161–162examples, 91–94external APIs, 101libraries, 93–94, 96–99names, 94–95pitfalls, 100–102servlets, 255–256strategies, 99–100vs. stubs, 90–95
Moore’s Law, 71Multithreaded code, 71–72
concurrent running, 79–82concurrent testing, 72–78parallel bit, 82–83
Mutable state, 383–385Mutable static fields, 11MyReporter class, 365–366MyTimeOutTransformer class, 328–329
name attribute<classes>, 447@DataProvider, 426<parameter>, 442<selector-class>, 443<suite>, 438<test>, 445
Namesmocks and stubs, 94–95test groups, 129–132
Nest and throw exception handling, 380–381-nogui parameter, 11–12
Beust.book Page 478 Monday, September 17, 2007 12:36 PM
Index 479
@NotTransactional annotation, 279NullPointerException class, 25, 160, 172–173
O complexity, 86Object factory, 284–286Object-oriented programming (OOP), 8–9Object-relational mapping (ORM) tools, 210Offline mode in EMMA, 142Online mode in EMMA, 142OOP (object-oriented programming), 8–9OpenJPA, 225, 234ORM (object-relational mapping) tools, 210Orthogonal test groups, 131Out-of-container Java EE testing, 198–199Output formats in Clover, 139Overhead for mocks, 102-overwrite option for JUnitConverter, 450
<package> tag, 331, 441–442Packages for test groups, 119–120<packages> tag, 441–442Painting code, 316–320Pair programming, 398parallel attribute
<suite>, 438–440<test>, 445
Parallel bit in multithreaded code, 82–83Parallel processing, 71–72
concurrent running, 79–82concurrent testing, 72–78parallel bit, 82–83
<parameter> tag, 441–442Parameterized Test Case pattern, 42–43, 469Parameters
annotations, 18data-driven testing, 42–50@DataProvider annotation, 47–59Eclipse, 408JUnit tests, 4testng.xml, 44–46
@Parameters annotation, 356, 426ParameterTest class, 19Participants in enterprise testing, 155Patterns, design. See Design patternsPercentages in code coverage, 148–149Performance testing, 83–87Persistence class, 232persistence.xml file, 227–229, 231–232, 234PersistenceAnnotationBeanPostProcessor bean, 236
PersistenceUnitInfo class, 232Person class, 225–226PersonManager class, 234–236, 240PersonManagerTests class, 235PictureTest class, 35, 37, 39Pitchfork project, 243–246PlatformTransactionManager class, 216, 276Plug-ins
Clover, 138–141Eclipse. See Eclipse plug-inIntelliJ IDEA. See IntelliJ IDEA plug-inJUnitReport, 361Report, 360
POJO-based objects, 225–226Polymorphism, 8Poolable objects, 212@PostConstruct annotation, 241@PostCreate annotation, 244@PreDestroy annotation, 244priority attribute, 443Private methods, 388–391PropertiesBasedJdbcDatabaseTester class, 296Providers
Data. See Data ProvidersJPA, 227–229
QA cycles in enterprise testing, 156Queues
ActiveMQ, 223–225Competing Consumers pattern, 182
Quick Fix command, 410–411, 453QuickSelectedTest class, 370-quiet option for JUnitConverter, 450
Raw HTTP requests, 261Real-world testing, 6Red bars in code coverage, 147Refactorings
enterprise testing, 186–193IntelliJ IDEA, 419servlets, 257
Reflection in Message-Driven Beans, 239Registering
Java EE tests, 203–204results listeners, 204–206service classes, 252
Regression testing, 157Regular expressions, 123Relative performance testing, 86–88Remote services tests, 254–255
Beust.book Page 479 Monday, September 17, 2007 12:36 PM
480 Index
@Repeat annotation, 278Reporter class, 360–361Reporter Output window, 359Reports
Clover, 141code coverage, 137, 148default, 355–358EMMA, 142–144error, 24–25formats, 137navigation, 137Report API, 360–366Reporter API, 360Test Classes view, 358–359TestNG, 355
RequestsJAX-WS, 248servlets, 261–262
Resource injection, 230–231Resource Locator pattern, 210Response time in algorithm complexity, 84–85Results listeners, registering, 204–206Return codes for reporting errors, 24Robertson, Jacob, 63Robot class, 312, 315Rollbacks in enterprise test setup, 168–170<run> tag, 446Runnable class, 468Running
concurrent, 79–82JUnit tests, 5test groups, 125–126
Runtimedesign pattern exceptions, 25–27Eclipse parameters, 408test groups, 122–125
RuntimeException class, 25
Scalability in big O notation, 85ScheduledDefaultValue class, 372ScheduledInTheFuture class, 372ScheduledInThePast class, 372ScheduledInvalidDate class, 372@ScheduledTest annotation, 368–369ScheduledTestSelector class, 369–370Scopes
annotation, 113–119methods, 391–392testng.xml, 437
<script> tag, 443<selector-class> tag, 443Selenium RC framework, 310–311Sender/receiver tests in JMS, 219–221sequential attribute, 428Servers
CI, 320–321embedded containers, 257–258
Service Locator patternEJB3, 236JNDI, 95, 190, 210
Service Provider Interface (SPI), 208Service test, 251–253ServiceLocator pattern, 214Servlet Filters, 193Servlets, 187–193, 255
embedded containers, 257–260in-container testing, 255in-memory invocation, 260–262mock/stub objects, 255–256refactoring, 257
Session beans, 240–243SessionMap class, 191–193Setup issues in enterprise testing, 166–171Shared states
immutable, 382–383mutable, 384–385
Shortcut syntax for JDK 5 annotations, 423SimpleNamingContextBuilder class, 209–210Simula language, 8SinglePageReporter class, 205SingleSpringContextTests class, 273Singleton class, 72–73Smoke tests, 130SOAP protocol, 246Source approach in code coverage, 146–147SPI (Service Provider Interface), 208Spring framework, 213–214, 270–271
AbstractAnnotationAwareTransactionalTests, 278–279
AbstractDependencyInjectionSpringContext-Tests, 274–275
AbstractSingleSpringContextTests, 273–274AbstractSpringContextTests, 272–273AbstractTransactionalDataSourceSpring-
ContextTests, 278AbstractTransactionalSpringContextTests,
276–278EJB3 layer, 243–244
Beust.book Page 480 Monday, September 17, 2007 12:36 PM
Index 481
features, 271–272JPA support, 231–236logging for, 395
spring-mock library, 94spring.xml file, 235SpringInjectionTests class, 274–275SpringTransactionTests class, 276–278-srcdir option for JUnitConverter, 450Stateful classes, 3–4Stateful tests, 382
immutable state, 382–383mutable state, 383–385
Statement coverage, 135States
ActiveMQ, 223–225maintaining, 461–462shared, 382–385
Static data in enterprise test setup, 167Static methods and fields in design, 11–14Static/source instrumentation in code coverage,
146–147Statistics for IntelliJ IDEA tests, 419StatusHandler class, 308Stub objects, 90
EJB3, 246enterprise testing, 161–162examples, 91–94vs. mocks, 90–95names, 94–95servlets, 255–256strategies, 99–100
Success, enterprise testing for, 161–163successPercentage attribute
annotation transformers, 354@Test, 428
<suite-file> tag, 442–443<suite-files> tag, 442–443suite method, 43, 458, 463–466<suite> tag, 331, 437–440Suite-wide initialization in JUnit migration, 463SuiteHTMLReporter reporter, 204–205suiteName attribute, 428Suites
Eclipse for, 406IntelliJ IDEA tests, 414–415TestNG framework, 18–19
Swallow and throw exception handling, 379Sweeney, Tim, 71
Swing UI, 312configuration, 313–314testing approach, 312–313usage, 314–316
Switch annotation style, 419Syntax for test groups, 120–122Synthetic XML files, 126, 333–334
TagsJavadocs, 421–422XML, 331, 437–447
TCP Monitor (tcpmon tool), 248TDD (test-driven development)
application difficulties, 386–387benefits, 388microdesign from, 385–386
TeamCity, 321–322@Test annotation, 19–20, 28–29, 427–428Test capture in enterprise testing, 156Test Classes view, 358–359Test data for enterprise testing, 163–165Test-driven development (TDD)
application difficulties, 386–387benefits, 388microdesign from, 385–386
Test groups, 119–120categories, 129–131excluding broken tests, 127–129names, 129–132running, 125–126runtime, 122–125syntax, 120–122
Test methods in data-driven testing, 42–50<test> tag, 331, 437, 444–445Testability in EJB3, 236TestCase class, 271TestHeavyClass class, 14–15Testing vs. encapsulation, 391–392TestListenerAdapter class, 326–327, 364testName attribute, 428@testng annotations, 421TestNG class, 200–201, 325–326, 428–[email protected] annotation, 425–[email protected] annotation, 426testng-failed.xml file, 32–34, 361, 436, 460–462TestNG framework
annotations. See AnnotationsBeanShell, 335–341
Beust.book Page 481 Monday, September 17, 2007 12:36 PM
482 Index
TestNG framework (continued)dependent testing with, 105–106groups, 20–21integration, 321–322method selectors, 341–346philosophy, 378reports, 355–366synthetic XML files, 333–334TestNG API, 325–331XML API, 331–333
@testng.parameters annotation, 426testng-single.xml file, [email protected] annotation, 427–428testng.xml file, 326, 435
vs. Data Providers, 59–60overview, 436–437packages in, 19passing parameters with, 44–46purpose, 21reports, 359sample, 331–332scopes, 437XML tags, 437–447
testngMethod variable, 339TestNGTest class, 462TestSuite class, 458TextMessage class, 160–161thread-count attribute, 79
<suite>, 438–439<test>, 445
Thread1Test class, 439–440threadPoolSize attribute
annotation transformers, 354parallelism, 185@Test, 73, 75, 77, 428
Threadsand dependent testing, 110–112multithreaded code, 71–72
concurrent running, 79–82concurrent testing, 72–78parallel bit, 82–83
time-out attribute, 445Time value, 397–399@Timed annotation, 279timeOut attribute
annotation transformers, 353<suite>, 438, 440@Test, 76–77, 428
Topics in Competing Consumers pattern, 182TopLink, 210, 225, 234Total Percentage Coverage (TPC), 139TransactionManager class, 216–217Transactions
enterprise test setup, 168–170Spring framework, 271, 276–278
Transformers, annotation, 346annotation history, 346–347pros and cons, 348usage, 353–355working with, 348–353
Unit tests, 129, 154, 157, 175–177UnsupportedOperationException class, 208Update site for Eclipse, 401–403URLConnection class, 259URLs for ActiveMQ configuration, 223UserAgentTest class, 43UserAppFactory class, 288UserAppModule class, 287UserAppObjectFactory class, 289UserDAO interface, 90–92, 282UserDAOStub class, 92UserLoginPanel class, 313–315UserManagement unit, 228UserManager interface, 90–93, 282–283UserManagerImpl class, 288UserTransaction class, 216–217
value attribute, 426, 442Value of time, 397–399Variables
BeanShell, 336, 338–339inspecting, 393static, 3
verbose attribute<suite>, 438<test>, 445
Web services. See Java API for XML Web Services (JAX-WS)
@WebService annotation, 247WebTest class, 116–117White-box code coverage testing, 132Whitespace in XML, 265WrappedConnection class, 170–171Wrapping exceptions, 381WsdlTest class, 466XDoclet, 347
Beust.book Page 482 Monday, September 17, 2007 12:36 PM
Index 483
Xerces library, 380–381XFire services, 247–249XML, 262–263
API, 331–333, 432–433for DbUbit, 296–297document testing, 253dom4j, 263–264synthetic files, 333–334tags, 331, 437–447XMLUnit, 264–265
XML over HTTP, 246XmlClass class, 331, 433
XmlFileFilter class, 181XmlMethodSelector class, 342XmlMethodsSelector class, 331, 433XmlPackage class, 331, 433XmlSuite class, 331–334, 364, 433XmlTest class, 331, 433, 466XMLTestCase class, 264XMLUnit, 264–265XNIException class, 304–305, 381XPath
JAX-WS, 253–254XML, 264
Beust.book Page 483 Monday, September 17, 2007 12:36 PM
Beust.book Page 484 Monday, September 17, 2007 12:36 PM