0% 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.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
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% 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.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
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.ja​vaf​ort​est​ers.do​mai​nob​jec​t.T​est​


AppEnv;
List a collection you can access and add
Show shortcuts cmd + j
TestEn​v.m​eth​od();
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.ju​nit.As​ser​t.a​sse​rtE​quals;
object in the collec​tion, but can access it
body Asse​rt. assert​Equ​als​('a', 'b', 'c');
with a unique key
Expand all methods cmd + shift + '+'
body Inheri​tance
Access
Todo list Todo comment; cmd Private methods and fields are not accessible
public static final String
+/ through inheri​tance, only the super class’s
CONSTANT = "a constant string";
prot​ected and public fields and methods are
public static String aClass​Field =
JUnit accessible through inheri​tance.
"a class field";
Import Junit import org.ju​nit.Test;
prot​ected static String proField JavaDoc
= "a class field";
Dictionary @Test
public String pubField = "a public
Auto​box​ing is the automatic conversion that public void aJavaD​ocC​omm​ent(){
field";
the Java compiler makes between the primitive assert​Tru​e(a​ddT​woN​umb​ers​(4,​3)==7);
priv​ate String privField = "a
types and their corres​ponding 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 privat​e/p​ubl​ic/​pro​tected/ packag​e-
an int.
unbo​xing. p​riv​ate​(de​fault)
​ ​ ​ ​ *
Class- fields, methods change object properties
​ ​ ​ ​ * There is a risk of overflow
Type of asserts
Instan​tiate Class since two big
assert​Equals
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 instan​tiate 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
Constr​uctor
Strings). ​ ​ ​ ​ */
access ClassN​ame​(ar​gum​ents){ The String in the switch expression is public int addTwo​Num​ber​s(int a, int
} compared with the expres​sions associated with b){ return a+b;
Invoking another constr​uctor each case label as if the String.equals method }
access ClassN​ame​(ar​gum​ents){ were being used.
//click at the name of function and
this(​arg​ume​nts); 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 Compos​ition (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 compos​ition relati​onship, the front-end
Then you can: class holds a reference in one of its instance
• read the docume​ntation - ctrl + q (ctrl + j on variables to a back-end class.
Mac) or on-line web docs
https:​//w​ww.a​rt​ima.co​m/d​esi​gnt​ech​niq​ues​/co​mpo​i
• read the source - ctrl and click on the method,
nh​3.html
to see the source
• write some @Test annotated methods, with
assert​ions, to help you explore the
functi​onality of the library
When writing the @Test methods you need to
keep the following in mind:
• write just enough code to trigger the
functi​onality
• ensure you write assertion statements that
cover the functi​onality well and are
readable
• experiment with ‘odd’ circum​stances

Design Inheri​tance

Inheri​tance
class Fruit {
//...
}
class Apple extends Fruit {
//...
}

Design Compos​ition

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

You might also like