CISC124 Assignment 3 due this Wednesday at 7pm.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Advertisements

Testing and Debugging CS221 – 2/13/09. Airline Program.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
Week 14 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Scalatest. 2 Test-Driven Development (TDD) TDD is a technique in which you write the tests before you write the code you want to test This seems backward,
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
Winter 2006CISC121 - Prof. McLeod1 Stuff We had better discuss a midterm date… –27 Feb. to 3 March or –6 to 10 March.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Today protected access modifier Using the debugger in Eclipse JUnit testing TDD Winter 2016CMPE212 - Prof. McLeod1.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
Winter 2006CISC121 - Prof. McLeod1 Last Time Reviewed class structure: –attributes –methods –(inner classes) Looked at the effects of the modifiers: –public.
Today Encapsulation. Build a fully encapsulated Halloween class, going from Halloween1 to Halloween6 (eventually!): –The final version will have overloaded.
Winter 2006CISC121 - Prof. McLeod1 Stuff Midterm exam in JEF234 on March 9th from 7- 9pm.
CISC124 - Notices Assn 2 due this Friday. You already know what you need to do this assignment: –Another procedural program. –Uses text file I/O (see Exercise.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Dept of Computer Science University of Maryland College Park
Computer Programming I
Chapter 3: Using Methods, Classes, and Objects
CISC/CMPE320 - Prof. McLeod
Barb Ericson Georgia Institute of Technology Dec 2009
Fall 2017 CISC124 9/18/2018 CISC124 First onQ quiz this week – write in lab. More details in last Wednesday’s lecture. Repeated: The quiz availability.
CMPE212 – Stuff… Assn 2 due next Friday. Winter 2018
Fall 2017 CISC124 9/21/2018 CISC124 First onQ quiz this week – write in lab. More details in last Wednesday’s lecture. Repeated: The quiz availability.
CISC/CMPE320 - Prof. McLeod
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
CISC124 Quiz 1 marking nears completion!
CMPE212 – Stuff… Assn 2 due this Friday. Winter 2018
Testing and Test-Driven Development CSC 4700 Software Engineering
CISC101 Reminders Assn 3 due Friday, this week. Quiz 3 next week.
Credit to Eclipse Documentation
Fall 2018 CISC124 12/1/2018 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
Fall 2018 CISC124 12/3/2018 CISC124 or talk to your grader with questions about assignment grading. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod.
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Debugging Taken from notes by Dr. Neil Moore
CISC124 Assignment 3 due tomorrow at 7pm.
Introduction to JUnit IT323 – Software Engineering II
CISC124 Assignment 4 on Inheritance due next Friday.
Fall 2018 CISC124 2/1/2019 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
CISC/CMPE320 - Prof. McLeod
CISC124 Labs start this week in JEFF 155.
CISC/CMPE320 - Prof. McLeod
CISC124 Labs start this week in JEFF 155. Fall 2018
CISC/CMPE320 - Prof. McLeod
Fall 2018 CISC124 2/22/2019 CISC124 Quiz 1 This Week. Topics and format of quiz in last Tuesday’s notes. The prof. (me!) will start grading the quiz.
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
Debugging Taken from notes by Dr. Neil Moore
CMPE212 – Reminders Assignment 2 due this Friday.
CMPE212 – Reminders Assignment 2 sample solution is posted.
CMPE212 – Reminders Assignment 3 due next Friday.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
CISC101 Reminders Quiz 1 marking underway.
Exceptions 25-Apr-19.
Exceptions 22-Apr-19.
CMPE212 – Reminders Assignment 2 due this Friday.
CMPE212 – Reminders Quiz 1 marking done. Assignment 2 due next Friday.
CMPE212 – Reminders Assignment 2 due in a week.
CMPE212 – Reminders Assignment 2 due today, 7pm.
CISC101 Reminders Assignment 3 due today.
CMPE212 – Reminders Assignment 2 due next Friday.
Exceptions 5-Jul-19.
Workshop for Programming And Systems Management Teachers
Presentation transcript:

CISC124 Assignment 3 due this Wednesday at 7pm. Fall 2018 CISC124 11/29/2018 CISC124 Assignment 3 due this Wednesday at 7pm. Quiz 2 next week, starting Monday at 8:30. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

Quiz 2 Topics Everything up to and including tomorrow’s material: Quiz 1 Java topics, but not Java History or Background (“How Java Works”). System, String, StringTokenizer, Wrapper classes. Method Overloading. Catching, Building and Throwing Exceptions. Aliasing Objects, Passing by Reference. 2D Arrays. Objects in general. Instantiation. Encapsulation – private attributes, constructors, accessors, mutators and other standard methods. Fall 2018 CISC124 - Prof. McLeod

Quiz 2 Topics, Cont. Exercises 1 to 9. File I/O from Exercise 5 – concepts only – you won’t have to write file I/O code. Unit Testing – concepts only – you don’t need to write testing code. TDD. You will be given a list of String methods if you need them. At least one coding problem. Otherwise, same rules as Quiz 1. Fall 2018 CISC124 - Prof. McLeod

Today Testing, Cont. Test Coverage in Eclipse. Debugging in Eclipse (if we have time). Fall 2018 CISC124 - Prof. McLeod

JUnit Testing in Eclipse, So Far We can harness methods for testing using assertions that can compare the expected results against the actual results of a method. The JUnit testing framework provides a way to carry out the tests in an independent way, in random order, to summarize results and to focus in on tests that have failed. Not every possible condition can be tested, but a reasonably full set of tests can give you some confidence… Fall 2018 CISC124 - Prof. McLeod

Some JUnit 5 Assertions Use (expected, actual) or (expected, actual, String). The optional argument is a string message that would describe what is being tested. assertArrayEquals() assertEquals() assertFalse() assertNotEquals() assertNotNull() assertNull() assertTrue() Fall 2018 CISC124 - Prof. McLeod

IllegalHalloweenException.class JUnit 5 Assertions, Cont. Use assertThrows() to make sure an exception is thrown when it should be. This assertion uses two arguments that are built using syntax we have not yet discussed. The two arguments are a Class object and an Executable object. The Class object: Any object has a .class constant attribute that supplies the Class object. So we use: IllegalHalloweenException.class to supply the Class object for the first argument, the expected exception type. Fall 2018 CISC124 - Prof. McLeod

JUnit 5 Assertions, Cont. The second argument is the Executable object. This will contain the code that is supposed to throw the identified exception. It is easiest to construct this object using a Lambda Function. Which we will discuss, just not yet! () -> new Halloween5(badYear, numKids, temps, condition) Fall 2018 CISC124 - Prof. McLeod

Halloween5Test.java, Cont. We looked at this program last time: Uses setup and teardown methods. Also uses assertThat (for a silly test…). Fall 2018 CISC124 - Prof. McLeod

Setup and Teardown Use @BeforeEach annotation with methods that will run before every test. Similarly @AfterEach for methods to run after every test. @BeforeAll runs once before all tests. @AfterAll runs once after all tests. Fall 2018 CISC124 - Prof. McLeod

assertThat() Takes a Matcher<T> object for its second (or third) argument. Possible object types: AllOf, AnyOf, BaseMatcher, CombinableMatcher, CustomMatcher, CustomTypeSafeMatcher, DescribedAs, DiagnosingMatcher, Every, FeatureMatcher, Is, IsAnything, IsCollectionContaining, IsEqual, IsInstanceOf, IsNot, IsNull, IsSame, StringContains, StringEndsWith, StringStartsWith, SubstringMatcher, TypeSafeDiagnosingMatcher, TypeSafeMatcher Fall 2018 CISC124 - Prof. McLeod

assertThat(), Cont. For example (from JUnit.org): And, there is a: assertThat("albumen", both(containstring("a")).and(containsString("b")) And, there is a: import static org.hamcrest.CoreMatchers.*; In the JUnit API docs look up this class for a list of these useful methods. Fall 2018 CISC124 - Prof. McLeod

assertThat, Cont. Note that the order is different - the actual comes first followed by the expected. You can still have a String message as the first parameter. You can build very sophisticated assertions with this method. Fall 2018 CISC124 - Prof. McLeod

No try/catch Don’t bother with try/catch blocks. If you are testing code that has a throws decoration, then just have your unit test method throw Exception to satisfy the compiler. If an exception is thrown unexpectedly (a run-time error!) you will get a different kind of failure notice in the report. Note that the testing does not stop! Fall 2018 CISC124 - Prof. McLeod

Test Suites You can combine separate JUnit testing classes into a single suite and run them all at once. In Eclipse, go “New”, “Other”, “JUnit”, “JUnit Test Suite”. This does not work properly in Eclipse and the JUnit5 instructions are not consistent! But you will not need to build a suite. Specify the src folder location for the existing testing *.java files and choose the ones you want to include in the suite. See AllTests.java. Fall 2018 CISC124 - Prof. McLeod

Advantages Tests are all separate from the code being harnessed. Very easy to add tests. Running tests is very simple and fast. Results are nicely summarized and you can zoom in on failed tests easily and get some decent diagnostics. Tests can be run on remote classes on a server, for example. Fall 2018 CISC124 - Prof. McLeod

Designing and Running Unit Tests Start by testing the most concrete independent methods first. Then test the methods that depend on these ones. Then test classes. Then test systems. Fall 2018 CISC124 - Prof. McLeod

Designing and Running Unit Tests, Cont. You will need to write stub and driver code as required in the testing classes. Stub code substitutes something “fake” to a method that depends upon it. Driver code simulates code that uses the method being tested. Keep the stub and driver code simple so that errors can only come from the harnessed code, not the testing code. Fall 2018 CISC124 - Prof. McLeod

Designing and Running Unit Tests, Cont. Start with tests that easily fall into the normal, expected range of inputs. Few or many? Use test generator tools? Create more tests for inputs that you suspect are related to each other. Choose tests for inputs that are just barely legal. Choose tests for inputs that are just barely illegal. Choose tests for inputs that are way out there! Make sure you exercise all the code being harnessed. Hundreds or thousands of tests! Fall 2018 CISC124 - Prof. McLeod

Designing and Running Unit Tests, Cont. Keep all tests unless you have deleted some of the methods/classes that you were testing. You can even leave these in with a “fail” call. Fixes applied to some methods can invoke a ripple effect, causing previously passed tests to fail. In a team effort always run (and pass) all of your unit tests before committing your code to the repository. Fall 2018 CISC124 - Prof. McLeod

Unit Testing You can never test all possible input conditions. Unit testing doesn’t prove that you code is without errors, but you can end up feeling pretty good about your code if it passes all tests. Fall 2018 CISC124 - Prof. McLeod

Test Driven Development or “TDD” Fall 2013 CISC124 Test Driven Development or “TDD” How much code can you “implement” without testing it? I get nervous writing 20 or 30 lines without testing. And whenever I complete a non-trivial method I test it. You should not separate the process of implementation and testing. Not surprising – this is a basic tenant of Agile Development. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

TDD, Cont. Is all about writing tests while you are writing, or decomposing your code. In fact the testing drives and leads the coding. We need a systematic technique to create tests that ensures coverage: Fall 2018 CISC124 - Prof. McLeod

TDD, Cont. The three Laws of TDD: You may not write production code until you have written a failing unit test. You may not write more of a unit test than what is sufficient to cause a failure, and not compiling is a failure. You may not write more production code than what is sufficient to pass the current failing test. Fall 2018 CISC124 - Prof. McLeod

TDD, Cont. So, tests should be written at the same time as the production code. You are always one test ahead of what the production code can pass. As the amount of production code grows so do the number of tests. Testing code should be in separate files from production code. It really helps to have some kind of framework to help organize and run these tests! Fall 2018 CISC124 - Prof. McLeod

Coverage Testing in Eclipse Run Debug Coverage Provides an easy way of seeing which lines of code have been covered by your testing code. Fall 2018 CISC124 - Prof. McLeod

Coverage Testing in Eclipse, Cont. Let’s run Coverage on Halloween5Test.java to see if we missed anything. Green – covered. Yellow – partially covered. (Conditional branch(s) missed, for example). Red – not covered. We did miss some tests! Fall 2018 CISC124 - Prof. McLeod

Coverage Testing in Eclipse, Cont. Getting rid of highlighting: Click here Uses a module called EclEmma. See: http://www.eclemma.org/ Fall 2018 CISC124 - Prof. McLeod

Debugging Sometimes a mental “walk-through” of your code is not enough to figure out an error. With the debugger you can run to a breakpoint, stop your program and then execute one line at a time while watching the call stack, variables and custom expressions. Let’s fix UseDebugger.java Fall 2018 CISC124 - Prof. McLeod

Debugging, Summary See “Java development users guide” > “Concepts” > “Debugger” and “Java development user guide” > “Getting Started” > “Basic tutorial” > “Debugging your programs” in the Eclipse help system. Place one or more breakpoints in your edit window. Run in debug mode. Use the “step” choices. View the method call stack, variables, and use expressions if needed. Fall 2018 CISC124 - Prof. McLeod

Aside – Skipping JRE Code in Debugger Goto Window > Preferences > Java > Debug > Step Filtering. Check all that apply: Then “Apply and Close”. Fall 2018 CISC124 - Prof. McLeod

Skipping JRE Code in Debugger, Cont. When in Debug mode: Turn on “Use Step Filters”: Now, you won’t see as much JRE code when you are stepping through your code. Fall 2018 CISC124 - Prof. McLeod