The document is a cheat sheet for Java testers, providing shortcuts for IntelliJ, explanations of collection interfaces, and JUnit usage. It covers concepts such as inheritance, composition, access control, and best practices for writing test methods. Additionally, it includes examples of JavaDoc comments and assertions in JUnit tests.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
13 views
Matiwan Java for Testers
The document is a cheat sheet for Java testers, providing shortcuts for IntelliJ, explanations of collection interfaces, and JUnit usage. It covers concepts such as inheritance, composition, access control, and best practices for writing test methods. Additionally, it includes examples of JavaDoc comments and assertions in JUnit tests.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
Java for Testers Cheat Sheet
by matiwan via cheatography.com/33684/cs/15111/
Shortcuts IntelliJ Collection interface Import
Show Parameters cmd + p Set a collection that does not allow Static import
Show JavaDoc ctrl + j duplicates usage com.javafortesters.domainobject.Test
AppEnv; List a collection you can access and add Show shortcuts cmd + j TestEnv.method(); elements at specific index positions Show popup definition alt + space Static import static Map a “key, value” pair where you store an Toggle all methods cmd + shift + - import org.junit.Assert.assertEquals; object in the collection, but can access it body Assert. assertEquals('a', 'b', 'c'); with a unique key Expand all methods cmd + shift + '+' body Inheritance Access Todo list Todo comment; cmd Private methods and fields are not accessible public static final String +/ through inheritance, only the super class’s CONSTANT = "a constant string"; protected and public fields and methods are public static String aClassField = JUnit accessible through inheritance. "a class field"; Import Junit import org.junit.Test; protected static String proField JavaDoc = "a class field"; Dictionary @Test public String pubField = "a public Autoboxing is the automatic conversion that public void aJavaDocComment(){ field"; the Java compiler makes between the primitive assertTrue(addTwoNumbers(4,3)==7); private String privField = "a types and their corresponding object wrapper } private field"; classes. For example, converting an int to an /** private String name; Integer, a double to a Double, and so on. If the * Add two integers and return conversion goes the other way, this is called private/public/protected/ package- an int. unboxing. private(default) * Class- fields, methods change object properties * There is a risk of overflow Type of asserts Instantiate Class since two big assertEquals A static method operates at the class level, * integers would max out the rather than the instance or object level. Which return int. means that we don’t have to instantiate the Switch statement * class into a variable in order to call a static A switch works with the byte, short, char, and * @param a is the first method. int primitive data types. It also works with number to add Superclass enumerated types (discussed in Enum Types), * @param b is the second the String class, and a few special classes that Access control number to add wrap certain primitive types: Character, Byte, * @return a+b as an int Short, and Integer (discussed in Numbers and Constructor Strings). */ access ClassName(arguments){ The String in the switch expression is public int addTwoNumbers(int a, int } compared with the expressions associated with b){ return a+b; Invoking another constructor each case label as if the String.equals method } access ClassName(arguments){ were being used. //click at the name of function and this(arguments); press ctrl+j }
By matiwan Not published yet. Sponsored by ApolloPad.com
cheatography.com/matiwan/ Last updated 15th June, 2018. Everyone has a novel in them. Finish Yours! Page 1 of 2. https://apollopad.com Java for Testers Cheat Sheet by matiwan via cheatography.com/33684/cs/15111/
Good practices Design Composition (cont)
When you encounter: }
• any Java library that you don’t know how to class Apple { use private Fruit fruit = new Fruit(); • parts of Java that you are unsure of //... • code on your team that you didn’t write and } don’t understand In a composition relationship, the front-end Then you can: class holds a reference in one of its instance • read the documentation - ctrl + q (ctrl + j on variables to a back-end class. Mac) or on-line web docs https://www.artima.com/designtechniques/compoi • read the source - ctrl and click on the method, nh3.html to see the source • write some @Test annotated methods, with assertions, to help you explore the functionality of the library When writing the @Test methods you need to keep the following in mind: • write just enough code to trigger the functionality • ensure you write assertion statements that cover the functionality well and are readable • experiment with ‘odd’ circumstances
Design Inheritance
Inheritance class Fruit { //... } class Apple extends Fruit { //... }
Design Composition
using instance variables that are references to
other objects class Fruit { //...
By matiwan Not published yet. Sponsored by ApolloPad.com
cheatography.com/matiwan/ Last updated 15th June, 2018. Everyone has a novel in them. Finish Yours! Page 2 of 2. https://apollopad.com