Introduction
This is an introductory text. At times it takes a tutorial approach and adopts step by step instructions to coding. Some people more familiar with programming might find this slow. This book is not aimed at those people.
This book is aimed at people who are approaching Java for the first time, specifically with a view to adding automation to their test approach. I do not cover automation tools in this book.
I do cover the basic Java knowledge needed to write and structure code when automating.
I primarily wrote this book for software testers, and the approach to learning is oriented around writing automation code to support testing, rather than writing applications. As such it might be useful for anyone learning Java, who wants to learn from a “test first” perspective.
Automation to support testing is not limited to testers anymore, so this book is suitable for anyone wanting to improve their use of Java in automation: managers, business analysts, users, and of course, testers.
Testers use Java differently
I remember when I started learning Java from traditional books, and I remember that I was unnecessarily confused by some of the concepts that I rarely had to use e.g. creating manifest files, and compiling from the command line.
Testers use Java differently.
Most Java books start with a ‘main’ class and show how to compile code and write simple applications from the command line, then build up into more Java constructs and GUI applications. When I write Java, I rarely compile it to a standalone application, I spend a lot of time in the IDE, writing and running small checks and refactoring to abstraction layers.
By learning the basics of Java presented in this book, you will learn how to read and understand existing code bases, and write simple checks using JUnit quickly. You will not learn how to build and structure an application. That is useful knowledge, but it can be learned after you know how to contribute to the Java code base with JUnit tests.
My aim is to help you start writing automation code using Java, and have the basic knowledge you need to do that. This book focuses on core Java functionality rather than a lot of additional libraries, since once you have the basics, picking up a library and learning how to use it becomes a matter of reading the documentation and sample code.
Exclusions
This is not a ‘comprehensive’ introduction. This is a ‘getting started’ guide. Even though I concentrate on core Java, there are still aspects of Java that I haven’t covered in detail, I have covered them ‘just enough’ to understand. e.g. inheritance, interfaces, enums, inner classes, etc.
Some people may look disparagingly on the text based on the exclusions. So consider this an opinionated introduction to Java because I know that I did not need to use many of those exclusions for the first few years of my automation programming.
I maintain that there is a core set of Java that you need in order to start writing automation code and start adding value to automation projects. I aim to cover that core in this book.
Essentially, I looked at the Java I needed when I started writing automation to support my testing, and used that as scope for this book. While knowledge of Interfaces, Inheritance, and enums, all help make my automation abstractions more readable and maintainable; I did not use those constructs with my early automation.
I also want to keep the book small, and approachable, so that people actually read it and work through it, rather than buying and leaving on their shelf because they were too intimidated to pick it up. And that means leaving out the parts of Java, which you can pick up yourself, once you have mastered the concepts in this book.
This book does not cover any Java 1.8 functionality. The highest version of Java required to work with this book is Java 1.7. The code in this book will work with Java 1.8, I simply don’t cover any of the new functionality added in Java 1.8 because I want you to learn the basics, and start being productive quickly. After you complete this book, you should be able to pick up the new features in Java 1.8 when you need them.
Windows and Mac supported
The source code was primarily written on Windows 7 and 8, using IntelliJ 13 and 14. But has also been run on Mac using IntelliJ 14.
Instructions are provided for installation, and IntelliJ usage, on both Mac and Windows.
Supporting Source Code
You can download the source code for this book from github.com. The source contains the examples and answers to exercises.
I suggest you work through the book and give it your best shot before consulting the source code.
The source code has been organized into two high level source folders: main and test. The full significance of these will be explained in later chapters. But for now, the test folder contains all the JUnit tests that you see in this book. Each chapter has a package and beneath that an exercises and an examples folder:
e.g.
- The main folder for Chapter 3 is:
-
src\test\java\com\javafortesters\chap003myfirsttest
-
- it contains an
examplesfolder with all the code used in the main body of the text - it contains an
exercisesfolder with all the code for the answers I created for the exercises in Chapter 3
This should make it easier for you to navigate the code base. And if you experience difficulties typing in any of the code then you can compare it with the actual code to support the book.
To allow you to read the book without needing to have the source code open, I have added a lot of code in the body of the book and you can find much of the code for the exercises in the appendix.
The Appendix “IntelliJ Hints and Tips” has information on loading the source and offers a reference section for helping you navigate and work with the source code in IntelliJ.
About the Author
Alan Richardson has worked as a Software professional since 1995 (although it feels longer). Primarily working with Software Testing, although he has written commercial software in C++, and a variety of other languages.
Alan has a variety of on-line training courses, both free and commercial:
- “Selenium 2 WebDriver With Java”
- “Start Using Selenium WebDriver”
- “Technical Web Testing”
You can find details of his other books, training courses, conference papers and slides, and videos, on his main company web site:
Alan maintains a number of web sites:
- SeleniumSimplified.com : Web Automation using Selenium WebDriver
- EvilTester.com : Technical testing
-
JavaForTesters.com : Java, aimed at software testers.
- JavaForTesters.com also acts as the support site for this book.
Alan tweets using the handle @eviltester
Acknowledgments
This book was created as a “work in progress” on leanpub.com. My thanks go to everyone who bought the book in its early stages, this provided the continued motivation to create something that added value, and then spend the extra time needed to add polish and readability.
Special thanks go to the following people who provided early and helpful feedback during the writing process: Jay Gehlot, Faezeh Seyedarabi, Szymon Kazmierczak, Srinivas Kadiyala, Tony Bruce, James ‘Drew’ Cobb, Adrian Rapan, Ajay Bansode.
I am also grateful to every Java developer that I have worked with who took the time to explain their code. You helped me observe what a good developer does and how they work. The fact that you were good, forced me to ‘up my game’ and improve both my coding and testing skills.
All mistakes in this book are my fault. If you find any, please let me know via compendiumDev.co.uk/contact or via any of the sites mentioned above.