0% found this document useful (0 votes)
70 views50 pages

Midterm 2 Review Sunday 1june2014

The document provides an overview of topics to be covered in a midterm review for a CSE 15L course. The topics include Git, TDD and JUnit, Makefiles, Unix shell scripting, XML and Ant, the Java Logging API, and profiling. For each topic, key concepts are outlined, such as the purpose of Makefiles, the format of XML documents, logging severity levels in Java, and tools for profiling memory usage and CPU performance.
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)
70 views50 pages

Midterm 2 Review Sunday 1june2014

The document provides an overview of topics to be covered in a midterm review for a CSE 15L course. The topics include Git, TDD and JUnit, Makefiles, Unix shell scripting, XML and Ant, the Java Logging API, and profiling. For each topic, key concepts are outlined, such as the purpose of Makefiles, the format of XML documents, logging severity levels in Java, and tools for profiling memory usage and CPU performance.
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/ 50

Midterm 2 Review

Ryan, Zack, Kristiyan, Jeffery, Alok

Goals of CSE 15L Team for weekly Labs:

Topics
1.
2.
3.
4.
5.
6.
7.

Git
TDD & JUnit
Makefile
Unix Shell Scripting
Ant & XML
Java Logging API
Profiling

Git

Git
Things you should know
What is git?
What is distributed version control?
What is centralized version control?
What is a push?
What does a staged file mean?
General git commands

Git

git status
Gives the status of all of the modified, newly added or newly removed files in the
local files
git log
Prints a log of all the recent git commands
git add
Stages a file to be committed
git remove
Removes a tracking of a file
git commit
Makes all the staged changes
git push
Puts all of the changes to a remote repo
git pull
Gets all the changes from a remote repo

Git Visualized

TDD & JUnit

Test Driven Development

JUnit is a tool for Test Driven Development [TDD]

In TDD, tests are written before the software itself.

You must understand the system before writing tests for it!

Regression testing -> change to code = build project + run tests

Unit Testing

What is a unit?
Unit is a single method! You are testing individual methods (units)
from the class they belong to!
Why should you use Unit Testing?
increased productivity
goal driven-code
and more...
Why you should not use it?
Does NOT test the full software
Consumes too much time
etc..

And now JUnit itself!

JUnit is a widely used framework for unit (remember what this is?) testing
of Java software!
JUnit:
Define and execute tests and test suites
Test Suites has many tests!
Write and debug code
and more

JUnit Terminology

Test fixture sets up the data needed to run tests.


Unit Test - A piece of code written by developer that executes a particular
part of the code being tested.
Test case - Tests the response of a single method to a particular set of
inputs.
Test suite - Collection of test cases.
Test runner - Software that runs your tests.
Integration test - how well classes work together. Not good in JUnit.

http://www.vogella.com/tutorials/JUnit/article.html <- Useful source!


http://ieng6.ucsd.edu/~cs15s/lab3/page3.html <- More info there!

Test in JUnit that returns without


failing or throwing an exception is
considered pass.

Failure happens when JUnit


assertion fails.

Goal for perfect implementation is to


pass all tests, and for imperfect is to
fail at least one test.

Other Frameworks

JUnit - JAVA
cppUnit - C++
PHPUnit - PHP
NUnit - .NET

All have: 1. Test Runner 2. Test Cases 3. Test fixtures 4. Test suites
5. Test Execution

Makefiles

Makefiles
Questions you should know the answer to about Makefiles
What is the point of a Makefile?
Why dont we just compile it again?
Why dont we just use a shell script?
What is the format of a Makefile?
How do we define variables in Makefiles?
How do we make in a subdirectory?

The Makefile Format


The format is just something you should memorize. Dependencies can be files.
If a dependency is more recent, than the target will be made.
Format:
target: dependencies
action

Basic Example:
default:
javac *.java
clean:
rm *.class
new: clean, default

The Makefile Format


Real Example:
CXX
DEFINES
CXXFLAGS
$(DEFINES)
INCPATH

= g++
= -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB
= -pipe -std=c++11 -O2 -Wall -W -D_REENTRANT -fPIE
= -I/software/common/qt-5.0.1/mkspecs/linux-g+

boggleutil.o: boggleutil.cpp boggleutil.h


$(CXX) -c $(CXXFLAGS) $(INCPATH) -o boggleutil.o boggleutil.cpp

Declaring Variables
For makefiles, we can define by simply creating a variable in all caps (by
convention) and setting it equal to a string. When we use the variable, it will be
replaced by the string we set it to.
Basic Example:
COMPILE
SRC

= javac
= *.java

$(COMPILE) $(SRC)

Real Example:
DEFINES
CFLAGS

= -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB


= -pipe -O2 -Wall -W -D_REENTRANT -fPIE $(DEFINES)

Making in a directory
To make in a subdirectory do:
make -C directory/ target

As an example there is:


make -C lib/ new

So in a makefile it may look like


clean:
make -C lib/ clean
make -C bin/ clean
rm *.class

Unix/Shell Scripting

Piping/Filtering

A pipe is a way to send the output of one command to another; the output
of the first becomes the input of the second
To make a pipe, put a vertical bar | on the commandline between two
commands
Examples:
ls -l | grep Apr
ls | wc -l
man ksh | grep "history" | wc -l
A filter is a program that takes input from another program and transforms
it in some way

Shell Scripting

Lines starting with # are comments, but the first line #! is not a comment; it
indicates the location of the shell that will be run

Quote characters
double quote: if a string is enclosed in the references to variables
will be replaced with their values
single quote: taken literally
` back quote: treated as command
echo Date is: `date`

Shell Scripting (declarations)

Array declarations:
y=(Hello hi hey)
To access declared variables, use $ and braces
echo ${y[0]} Hello is printed

Declarations must not include spaces around equals sign

Shell Syntax

Instead of using braces {} to control logic flow and statement blocks, shell
uses terminating words:
if, then/ fi
for i in {1..10}
case / esac
do
for, do, done
if [ $[i % 2] = 1 ]; then
while, do, done
echo $i is odd
else
echo $i is even
fi
done

Examples
for (( c=1; c<=5; c++ ))
do
echo "Welcome $c times"
done
__________________________
c=0
while [ $c -lt 10 ]
do
echo The counter is $c
let c=c+1
done

echo Enter a fruit:


read fruit
case $fruit in
apple)
echo Apple
;;
banana)
echo Banana
;;
*)
echo Something else
;;
esac

Examples (more)
ls | while read line
do
echo Hello ${line}!
done
_______________________
filename=$1
while read line
do
echo Hello ${line}!
done < $filename

filename=$1
cat $filename | while read line
do
echo Hello ${line}!
done

What you should know

Know the difference between echo and cat


Variable declarations
How to call variables
How strings , ``, work in bash
How to use simple constructs like if statements, for loops, etc
Commands like cd, rm, mv, cp, etc

Site to test:
http://www.compileonline.com/execute_bash_online.php

XML & Ant

XML

Sibling of HTML
<tag></tag> and <title></title> and <midterm></midterm>
XML Data Components
Elements
Hierarchical structure with open-close tag pairs
Nesting, same names is allowed, order matters
<review mdate=2014-06-01...>
<presenter>Kristiyan Dzhamalov</presenter>
</review>
Attributes
named values are not hierarchical, order does NOT matter
mdate=2014-06-01

XML Example
<review>
<presenter name=Kristiyan >
<topic>Ant</topic>
<topic>XML</topic>
<topic>JUnit</topic>
</presenter>
<presenter name=Zack>
<topic>Makefile</topic>
</presenter>
and more
</review>

Ant - Another Neat Tool

Tool for automated software builds - Very useful in industry with Java dev.
Similar to make
Uses XML to describe the building process and its dependencies
By default the XML file is named build.xml
You can obtain the value of a variable using ${property_name}
How to make a variable?
<property name=public.dir location=public />

Ant - Cont.

Each Ant XML file contains:


1 project and at least 1 target
Targets have multiple tasks
Projects contain 3 attributes - name, default and basedir
<project name=MidRev2 default=jar basedir=.>
default means which target to compile if not specified
Target contains a name and optionally depends and description
There can be dependencies between targets
Task represents an action that needs execution

Read lecture slides and lab

Java Logging API


Link to lecture slide

Java Logging API


Why use it?
The Java Logging API provides a standardized
process of logging statements (automatically
recording diagnostic output from a program)
Better than using System.out.println() statements
scattered throughout your code
You can leave all logging statements in your code
and control which ones are printed out using
logging.properties file

General Concepts
Each log message has an associated log Level
The Level class specifies the importance and urgency of
a log message
Seven standard log levels ranging from FINEST (the
lowest priority) to SEVERE (the highest priority).

Severity Levels (Descending order)


1.
2.
3.
4.
5.
6.
7.

SEVERE: Used for logging fatal runtime error events


WARNING
INFO
CONFIG
FINE: Usually at the level of object creation, catch clauses for exceptions
that do not constitute errors, and so on.
FINER: Entering and exiting should be used for tracing method entry and
exit; arguments and return values can be specified.
FINEST: This level of tracing can be used to track the state of instance
variables in a class e.g. before a method call, inside a method or a loop
and after a method call.

Tracing
Tracing involves logging messages which
report the state of the application at different
stages of execution
Useful for following the flow of your program

Loggers and Handlers


Loggers are objects that allow the application to log
without regard to where the output is sent/stored
Handlers receive the log message from the logger and
export it to a certain target.
Examples of Handlers:
ConsoleHandler: Write the log message to console
FileHandler: Writes the log message to file

Profiling

Profiling
- Why ?
- What ?
- How ?

What ?

Memory
CPU Usage
HDD Usage (Swap files etc)
Network Usage
Battery
In short, any resource that your
application depends on

How ?

hprof

hprof
heap=dump|sites|all
This option helps in the analysis of memory usage.
It tells HPROF to generate stack traces, from which
you can see where memory was allocated.
heap=dump option, you get a dump of all live objects in the heap.
heap=sites, you get a sorted list of sites with the most heavily allocated
objects at the top.
The default value all gives both types of output.

hprof

hprof

UNIX Time

Thank you !

Have a nice Summer !

You might also like