Swipe to navigate through the chapters of this book
It seems appropriate to start learning about Spring by building out our first example as a simple "Hello, World!" application. In this chapter, we’re going to take a look at the tools and libraries we’re going to rely on – in particular, Gradle and TestNG – and build a simple application to demonstrate how we validate that our application works as designed. Then – at last – we’ll leverage Spring in our application. This way, we’ll establish the knowledge we’ll need to make sense of the rest of the book.
Please log in to get access to this content
Why TestNG and not JUnit? There’s a little more explanation later in this chapter, but just to get it out of the way: TestNG makes certain kinds of tests more convenient. You should be able to use JUnit instead with fairly little difficulty, although you’ll need to add a JUnit module to use features like data providers.
We’re foisting a “Hello world” on you, but we promise there’s no “Pet Store” in this book. If that doesn’t give you a palpable sense of relief, well… pretend it does, because it should. Right, Joe? We’re not doing the Pet Store, right? We agreed? Yes?
If you don’t write tests, you need to start writing tests. Don’t worry, you’ll get a ton of exposure in this book. They’re easy and fun. After your first 1,203,172 tests, you might get a free toaster.
Kernighan, Brian & Ritchie, Dennis (1978), Englewood Cliffs, NJ; Prentice-Hall.
Gradle can be found at https://gradle.org . We’ll demonstrate how to install Gradle for many operating systems as we go through the chapter.
If your operating system is not addressed, fear not, Brave Reader: http://gradle.org/ can help.
SDKMAN! ( https://sdkman.io/ ) is a developer-focused environment manager for multiple operating systems, including Linux, Windows, and OSX. It allows you to have localized environments for building and running applications. It’s horribly useful, because it disassociates you from the distribution’s package-management process.
Homebrew ( https://brew.sh/ ) is essential if you run MacOS, so if you don’t have it installed already, for the love of all that is good and holy, do it now.
Scoop ( https://scoop.sh/ ) is a simple command line installer for Windows.
TestNG utilized the concept of data providers before JUnit did, and while JUnit supports the feature now it’s through a library external to JUnit. We’ve chosen to stick with TestNG, but you can certainly use JUnit instead without hurting our feelings very much; JUnit’s nearly caught up with TestNG and in some ways has surpassed it.
Using static imports in your regular code is a code smell, and you don’t want your code to smell funky, do you? … No, you don’t.
We’ll be showing you programmatic Spring context configuration in Chapter 3.
Worth noting: Not remembering the proper inheritance bit the author for about 30 minutes before he realized that he’d forgotten the required class hierarchy.
I promise the next chapter will fly by, configuration talk is super exciting.
- Hello, World!
Joseph B. Ottinger
- Sequence number
- Chapter number
- Chapter 2