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.

Slides:



Advertisements
Similar presentations
T ESTING WITH J UNIT IN E CLIPSE Farzana Rahman. I NTRODUCTION The class that you will want to test is created first so that Eclipse will be able to find.
Advertisements

16-Jun-15 javadoc. 2 Javadoc placement javadoc comments begin with /** and end with */ In a javadoc comment, a * at the beginning of the line is not part.
Object-Oriented Enterprise Application Development Javadoc Last Updated: 06/30/2001.
Fall 2007CS 2251 Programming Tools Eclipse JUnit Testing make and ant.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
Program documentation using the Javadoc tool 1 Program documentation Using the Javadoc tool.
Documentation Dr. Andrew Wallace PhD BEng(hons) EurIng
Javadoc Dwight Deugo Nesa Matic
JavaDoc and Contracts Spring Documenting Contracts with JavaDoc Contract model for methods Preconditions Postconditions JavaDoc Industry standard.
JUnit A framework which provides hooks for easy testing of your Java code, as it's built Note: The examples from these slides can be found in ~kschmidt/public_html/CS265/Labs/Java/Junit.
A brief introduction to javadoc and doxygen. What’s in a program file? 1. Comments 2. Code.
Javadoc Summary. Javadoc comments Delemented by /** and */ Used to document – Classes – Methods – Fields Must be placed immediately above the feature.
Page 1 – Autumn 2009Steffen Vissing Andersen SDJ I1, Autumn 2009 Agenda: Java API Documentation Code Documenting (in javadoc format) Debugging.
Java Doc Guideline R.SANTHANA GOPALAN. Java Doc Guideline Audience Internal Developers PQA - who write test plans PPT – who write the documentation Customers.
Winter 2006CISC121 - Prof. McLeod1 Stuff We had better discuss a midterm date… –27 Feb. to 3 March or –6 to 10 March.
JUnit Testing Why we do this and how we can get better.
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.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
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.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Advanced Programing practices
More Sophisticated Behavior
CMPE212 – Stuff… Assn 2 due next Friday. Winter 2018
CMPE212 – Stuff… Assn 3 due and Quiz 2 in the lab next week.
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.
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
Introduction to javadoc
Some Tips for Using Eclipse
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 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
CISC124 Quiz 1 marking nears completion!
CISC124 Assignment 3 due this Wednesday at 7pm.
CMPE212 – Stuff… Assn 2 due this Friday. Winter 2018
Test-driven development (TDD)
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.
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CISC124 Assignment 4 on Inheritance due next Friday.
CISC124 Assignment 3 due tomorrow at 7pm.
Introduction to JUnit IT323 – Software Engineering II
CISC124 Assignment 4 on Inheritance due next Friday.
JavaDoc and Contracts Fall 2008.
CISC124 Labs start this week in JEFF 155.
CISC124 Labs start this week in JEFF 155. Fall 2018
CISC/CMPE320 - Prof. McLeod
Advanced Programing practices
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,
CISC124 Assignment 3 sample solution will be posted tonight after 7pm.
Introduction to javadoc
CMPE212 – Reminders Assignment 2 due this Friday.
CISC101 Reminders All assignments are now posted.
CMPE212 – Reminders Assignment 2 sample solution is posted.
CMPE212 – Reminders Assignment 3 due next Friday.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
JUnit Reading: various web pages
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.
Winter 2019 CMPE212 5/25/2019 CMPE212 – Reminders
Review of Previous Lesson
CMPE212 – Reminders Assignment 2 due next Friday.
Workshop for Programming And Systems Management Teachers
Presentation transcript:

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 Week 8 (this is week 6). A sample solution to Assignment 2 is posted (includes the answers to the questions). Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

Today Documentation using Javadoc comments. Adding the JUnit5 library to your Assn 3 project in Eclipse. Start JUnit Testing. Fall 2018 CISC124 - Prof. McLeod

Fall 2013 CISC124 Javadoc Javadoc.exe is a program that comes with the JDK. (It is in the same directory as javac.exe and java.exe – the “bin” folder). It is not included in the JRE only. If I have written a class, “MyClass.java”, that contains properly formatted comments (more below), then running “javadoc MyClass.java” generates a file “MyClass.html”. The html file contains external documentation generated from the formatted comments in the source code. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod

Javadoc - Cont. Normal block comments in Java are delimited by “/*” and “*/”. Everything between these delimiters, usually multiple lines, is a comment. Javadoc block comments are delimited by “/**” and “*/”. Fall 2018 CISC124 - Prof. McLeod

Javadoc - Cont. The general form of a Javadoc comment: /** * Summary sentence. * More general information about the * class, attribute or method which * follows the comment, using as many lines * as necessary. (html tags can be included) * * javadoc tags to specify more specific * information, such as parameters and * return values for a method */ Fall 2018 CISC124 - Prof. McLeod

Javadoc - Cont. The general form of a Javadoc tag is: @tagName comment The tags you use depend on what you are describing (class, method or attribute). In the case of methods, you can have a tag for each parameter, the return value, and a tag for each thrown exception. Eclipse (really nice!!) will generate the needed blank tags for you after you type “/**” above a method name. Typically, you will only write javadoc comments for public attributes and methods… Fall 2018 CISC124 - Prof. McLeod

Eclipse Javadoc Assist For example, if you have the method header: public static double[] generateRandomArray(int size) Type /** right above this line and press <enter>. You will get: /** * * @param size * @return */ Fall 2018 CISC124 - Prof. McLeod

Eclipse Javadoc Assist, Cont. Then you have to finish the comment: /** * Generates an array of random doubles. * * The method uses the Math.random() method to generate * an array of doubles between 0.0 and 1.0. * @param size The desired size of the array. * @return The array of random doubles. */ Fall 2018 CISC124 - Prof. McLeod

Eclipse Javadoc Assist, Cont. Hold your cursor over the method header and you will get a preview of what the processed Javadoc will look like: (Or view the Javadoc tag in the same view as the Console tag.) Fall 2018 CISC124 - Prof. McLeod

Common Javadoc Tags @param Parameter_name description @throws Exception_name description @return description @see packageName.ClassName, packageNamme.ClassName#methodName, etc. @author @version Fall 2018 CISC124 - Prof. McLeod

Javadoc - Cont. Html tags can also be added to the comments to add more formatting to the resulting document: <em> for emphasis <code> for code font <img> for images <ul><li> </li></ul> for bulleted lists Etc… Fall 2018 CISC124 - Prof. McLeod

Javadoc Reference The best reference for javadoc is at: http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html Fall 2018 CISC124 - Prof. McLeod

Javadoc - Cont. The output from Javadoc looks exactly like the API documentation you have already seen - since that is the way it has been generated! The advantage is that when source code is changed, the Javadoc comments can be changed in the source, at the same time. The external documentation is then easily re-generated. Javadoc also provides a consistent look and feel to these API documents. Fall 2018 CISC124 - Prof. McLeod

Javadoc - Cont. Most modern IDE’s (like NetBeans and Eclipse) allow you to run Javadoc from within the environment, and provide tools and wizards to help you create comments. In Eclipse, select “Project”, then “Generate Javadoc…”. Let’s run javadoc on the Halloween5 class. (Note that the first time you do this, you will have to tell Eclipse where javadoc.exe resides.) Fall 2018 CISC124 - Prof. McLeod

Testing in Assignment 3 You are supplied with JUnit5 testing programs to test your Pizza and LineItem classes. JUnit testing is the established and best way to test Java programs. JUnit testing will be covered in class (starting today!), but you don’t need to understand JUnit testing to run the testing programs – you do not need to write any new tests and should not modify the existing tests. Fall 2018 CISC124 - Prof. McLeod

Testing in Assignment 3, Cont. To run the supplied tests you will need to link the JUnit 5 library to your assignment 3 project. The wizard that creates a JUnit testing class can do this for you or you can: First, right click on the project name, choose “Build Path”, then “Add Libraries…” Fall 2018 CISC124 - Prof. McLeod

Testing in Assignment 3, Cont. Choose “JUnit”. Then “Next >”. On the next screen, make sure that JUnit 5 is chosen and click on “Finish”. Fall 2018 CISC124 - Prof. McLeod

Testing in Assignment 3, Cont. If you already have the testing classes in your project, then all those errors should go away! You can run the JUnit testing files on their own. The “suite” program just runs both of them together. Fall 2018 CISC124 - Prof. McLeod

Testing Until now “we” have used another class with a main method to run tests on the class we have “harnessed” for testing. See TestHalloween4.java and TestHalloween5.java for example. JUnit is a framework designed for this kind of work and it is very easy to use in Eclipse. Fall 2018 CISC124 - Prof. McLeod

JUnit Testing Best reference is junit.org See the links in the centre column and the API docs. For use in Eclipse see: “Java development user guide” > “Getting Started” > “Basic tutorial” > “Writing and running JUnit tests”. Fall 2018 CISC124 - Prof. McLeod

JUnit Testing in Eclipse In the project containing the class(es) you wish to test, add a Testing class by choosing “New JUnit Test Case”: Name the class and choose the classes to be tested. Choose extra stubs, if needed. Fall 2018 CISC124 - Prof. McLeod

JUnit Testing in Eclipse, Cont. Next, let the wizard create test method stubs in your testing class for all methods you wish to test: Fall 2018 CISC124 - Prof. McLeod

JUnit Testing in Eclipse, Cont. Allow the wizard to add the JUnit library to the Build Path, if prompted. Fall 2018 CISC124 - Prof. McLeod

JUnit Testing in Eclipse, Cont. Fill in the method stubs with tests. You can have multiple tests in a method or multiple methods or both, as required. You could end up with hundreds of tests, just for one object! See Halloween5Test.java. It contains one test that will not pass – just to show what a failed test looks like. Fall 2018 CISC124 - Prof. McLeod

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 are 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. 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) parameter. 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 more 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