Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS427: Software Engineering I

Similar presentations


Presentation on theme: "CS427: Software Engineering I"— Presentation transcript:

1 CS427: Software Engineering I
Grigore Rosu

2 Today’s goals Quick Logistics Testing 1 Quiz 1 discussion
jUnit – basic notions, demo by Tao Mo Selenium – very basic notions, demo by Yi Zhang

3 Course Logistics Wiki: (videos!) Piazza: Compass: All class-wide announcements through compass or my.cs MP1 due today, 23:59; MP2 due Monday, 23:59 Follow the rules and the format specified on Wiki! Office hours by request (Piazza) Qing Ye also offers regular office hours on Tu/Th 3-4pm, SC4105 Used also for makeup quizzes: Mon quiz ~> Tu; Wed quiz ~> Th Reminder MPs (30%), final exam (25%), project (40%), quizzes (5%) Bonus up to 3% for active participation (lectures, Piazza, …) Lots of “broad but shallow” reading Read, read, read everything we list on the wiki Book chapters and papers will be on EXAM

4 Quiz 1 Discussion - General -
Regular office hours? Yes, we have those too, now Makeup quizzes? Yes: take makeup quiz next day at regular office hour Make announcements clear, both on Piazza and Compass Will do

5 Quiz 1 Discussion - Lectures -
Speak louder; make sure microphone is working Will do; you should also tell me during class Too dry/boring/theoretical sometimes, not interesting / useful, feels like a business class Will try to add more pictures, more real-life examples and experiences; do more interactive activities; trends in industry, transformative/disruptive products Some contradictory messages: More general concepts! More specific concepts! Lectures and MPs should be more related Will discuss the MPs more in class, demos

6 Quiz 1 Discussion - MPs - Excellent, love them, useful! Clear, easy to understand! Confusing, not clear what is required; too antique, need to be modernized; feel random, unrelated  Will do our best to make things clearer Note that we inherited them Related to project Rounds of autograding? Probably not feasible this semester; will do in the future

7 Testing 1 jUnit Selenium

8 Goals Why test and what are major terminologies in testing?
How to use JUnit to write unit tests?

9 Why test? Improve quality – find faults (or defects, or bugs)
Measure quality Prove there are no faults? (Is it possible?) Determine if software is ready to be released Determine what to work on See if you made a mistake Learn the software

10 What is a test? Run program with known inputs (test inputs/data), check results (with test oracles) Tests pass (green) or fail (red) Tests can document faults Tests can document code Important terminology to remember: Mistake, fault (or defect, or bug), failure, error Oracle

11 Recall Terminology: Mistake, Fault/Bug, Failure, Error
Programmer makes a mistake Fault (defect, bug) appears in the program Fault remains undetected during testing Program failure occurs during execution (program behaves unexpectedly) Error: difference between computed, observed, or measured value or condition and true, specified, or theoretically correct value or condition

12 Terminology: Mistake, Fault/Bug, Failure, Error
Running the test inputs … Programmer makes a mistake Fault (defect, bug) appears in the program Fault remains undetected during testing Program failure occurs during execution (program behaves unexpectedly) Error: difference between computed, observed, or measured value or condition and true, specified, or theoretically correct value or condition

13 Terminology: Mistake, Fault/Bug, Failure, Error
Based on test oracles … Programmer makes a mistake Fault (defect, bug) appears in the program Fault remains undetected during testing Program failure occurs during execution (program behaves unexpectedly) Error: difference between computed, observed, or measured value or condition and true, specified, or theoretically correct value or condition

14 Terminology: Mistake, Fault/Bug, Failure, Error
What does bug mean in “bug report”? Programmer makes a mistake Fault (defect, bug) appears in the program Fault remains undetected during testing Program failure occurs during execution (program behaves unexpectedly) Error: difference between computed, observed, or measured value or condition and true, specified, or theoretically correct value or condition

15 Where is fault, error, or failure?
Objective: double the balance and then add 10 int calAmount () { int ret = balance * 3; ret = ret + 10; return ret; } Where is test input? Where is test oracle? void testCalAmount() { Account account = new Account(); account.setBalance(0); int amount = account.calAmount(); assertTrue(amount == 10); }

16 Where is fault, error, or failure?
Objective: double the balance and then add 10 int calAmount () { int ret = balance * 3; ret = ret + 10; return ret; } Where is test input? Where is test oracle? Is this a good test? void testCalAmount() { Account account = new Account(); account.setBalance(0); int amount = account.calAmount(); assertTrue(amount == 10); }

17 Where is fault, error, or failure?
Objective: double the balance and then add 10 int calAmount () { int ret = balance * 3; ret = ret + 10; return ret; } Try some input different from 0? void testCalAmount() { Account account = new Account(); account.setBalance(1); int amount = account.calAmount(); assertTrue(amount == 12); }

18 Where is fault, error, or failure?
Objective: disallow withdrawal when balance is 100 or less boolean doWithdraw(int amount) { if (balance < 100) return false; else return withDraw(amount); } void testWithDraw() { Account account = new Account(); account.setBalance(100); boolean success = account.doWithdraw(10); assertTrue(!success); }

19 Who should test? Developer / programmer?
Separate “quality assurance” group? User? Someone with a degree in “testing”?

20 What kind of tests? Programmer tests / non-programmer tests
Developer / Tester Unit tests / Integration tests / Functional tests / System tests Automated tests / Manual tests Regression tests Exploratory testing

21 What kind of tests? Manual Automatic Good for exploratory
Good for testing GUI Manual regression testing is BORING Automatic Test is a program Test is created by a tool that records user actions

22 Test automation Tests are code or scripts (which is code)
Real projects can often have more test code than production code Test code is boring Build some complex data values Run a function Check the result

23 xUnit testing tools Programmer’s testing tools Automated testing!
Unit testing, but also integration testing and functional testing Regression testing Test-first design Each code unit requires several tests

24 What is JUnit? Open source (junit.org) Java testing framework used to write and run repeatable automated tests A structure for writing test drivers JUnit features include: Assertions for testing expected results Sharing common test data among tests Test suites for easily organizing and running tests Test runners, both graphical and textual JUnit is widely used in industry Can be used as stand alone Java programs (from command line) or from an IDE such as IntelliJ or Eclipse Introduction to Software Testing (Ch 1) © Ammann & Offutt

25 JUnit Tests JUnit can be used to test …
… an entire object … part of an object – method or interacting methods … interaction between several objects Primarily unit & integration testing, not system testing Each test is embedded into one test method A test class contains one or more test methods Test classes include: A test runner to run the tests - main() A collection of test methods Methods to set up the state before and update the state after each test and before and after all tests Get started at junit.org Introduction to Software Testing (Ch 1) © Ammann & Offutt

26 Writing Tests for JUnit
Need to use methods of junit.framework.assert class javadoc gives a complete description of its capabilities Each test method checks a condition (assertion) and reports to the test runner whether the test succeeded or failed The test runner uses the result to report to the user (in command line mode) or update the display (in an IDE) All of the methods return void A few representative methods (of junit.framework.assert): assertTrue(boolean) assertTrue(String, boolean) assertEquals(Object, Object) assertNull(Object) Fail(String) Introduction to Software Testing (Ch 1) © Ammann & Offutt

27 Example JUnit Test Expected result The test public class Calc {
public long add (int a, int b) return a + b; } Expected result import org.junit.Test; import static org.junit.Assert.*; public class calcTest { private Calc calc; @Test public void testAdd() calc = new Calc (); assertEquals((long) 5, calc.add(2,3)); } The test Introduction to Software Testing (Ch 1) © Ammann & Offutt

28 Sample Assertions For a complete list, see
static void assertEquals(boolean expected, boolean actual)           Asserts that two booleans are equal static void assertEquals(byte expected, byte actual)           Asserts that two bytes are equal static void assertEquals(char expected, char actual)           Asserts that two chars are equal static void assertEquals(int expected, int actual)           Asserts that two ints are equal static void assertEquals(double expected, double actual, double delta)           Asserts that two doubles are equal, within a delta static void assertEquals(float expected, float actual, float delta)           Asserts that two floats are equal, within a delta For a complete list, see Introduction to Software Testing (Ch 1) © Ammann & Offutt

29 Junit DEMO (Tao Mo)

30 MP1 and MP2 Who to talk to about
Daejun Park: MP1 - Exercise 1 & 2 (Maven, JSP) Tao Mo: MP1 - Exercise 3 (JDBC) Yi Zhang: MP2

31 Selenium How do we test web applications?
Challenges: heterogeneity, dynamicity, security Selenium Tool set that automates web app testing across platforms Can simulate user interactions in browser Two components Selenium IDE (has some limitations) Selenium WebDriver (aka. Selenium 2)

32 Selenium DEMO (Yi Zhang)

33 MP1 and MP2 Who to talk to about
Daejun Park: MP1 - Exercise 1 & 2 (Maven, JSP) Tao Mo: MP1 - Exercise 3 (JDBC) Yi Zhang: MP2


Download ppt "CS427: Software Engineering I"

Similar presentations


Ads by Google