1 / 17

SENG 301 – Tutorial 1

Learn how to acquire and use Eclipse, Subclipse, and JUnit for Java development and testing. Includes step-by-step instructions, tips, and best practices.

msalas
Download Presentation

SENG 301 – Tutorial 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SENG 301 – Tutorial 1 Introduction to Eclipse, Subclipse, and JUnit Slides: Theodore D. Hellmann

  2. Acquiring the Software - 1 Eclipse: - download “Eclipse Classic” from eclipse.org - remember it just unzips (no installation)‏ JUnit: - JUnit 3.4 and 4.3 comes with Eclipse - 4.5 is out; you can get it from junit.org

  3. Acquiring the Software - 2 • Subclipse: • 1) Start Eclipse • 2) Under the “Help” menu, click “Software Updates”, then select the “Available Software” tab • 3) Click “Add Site…” and type in http://subclipse.tigris.org/update_1.4.x • 4) Click the “OK” button, select the checkbox next to Subclipse, and click “Install…”

  4. Using Eclipse - 1 First create a new project: - click on “File”, then “New”, then “Java Project” Next, create a new class: - click “File”, then “New”, then “Class” To run your code: - click on the “Run” menu, then on “Run”

  5. Using Eclipse - 2 Some useful features: - Catches syntax errors while you code - Hover over an error (squiggly red line) for suggestions on how to fix it - Auto-Complete

  6. Using Subclipse - 1 Before you can use Subclipse: - email help@cpsc.ucalgary.ca and ask for an SVN account - the email should look something like “Hi, I need an SVN account for [your username], and the following people will need to be able to access it: [your partner’s usernames]” Standard operating procedure is to CC Dr. Sillito

  7. Using Subclipse - 2 Help’s response will contain: - the link you’ll need to use when initially sharing the project and when accessing it - it should look something like: https://forge.cpsc.ucalgary.ca/svn/courses/s301/ group[your group number here]

  8. Using Subclipse - 3 To share a project: - create a project in Eclipse - right-click the project, hover over “Team” in the context menu, and click “Share Project…” - double-click “SVN”, then enter in the URL that Help sent you

  9. Using Subclipse - 4 To access a shared project: - click on “Window”, hover over “Open Perspective…”, then click on “Other” - select “SVN Repository Exploring” from the list - next, right-click within that perspective, hover over “New”, then select “Repository Location” - enter in the URL, after which you will likely be prompted for your username and password

  10. Using Subclipse - 5 The main commands you will use in Subclipse: Update: will check the repository for changes and add them to your code Commit: takes changes in your code and adds them to the server Merge: resolves conflicts discovered by either of the above operations

  11. Using Subclipse - 6 The main commands you will use (continued): Synchronize: - allows you to select which changes to make to both code bases if there have been concurrent modifications - otherwise Subclipse may insert junk into your code!

  12. Using Subclipse - 7 To take any of these actions: - right-click on your project, hover over “Team”, then select the action you want from the menu If you Update/Commit frequently, you’ll reduce the chance of creating a conflict, and also reduce the time it takes to sort a conflict out!

  13. Testing - Definitions There are two main types of testing that JUnit is good for: Unit Testing - checks whether a subset of your project is working; for example that an individual method is performing as expected Acceptance Testing - checks whether your code as a whole is performing as expected

  14. JUnit Testing - 1 To create a JUnit test class: - go to “File”, then “New”, then “JUnit Test Case” - type the name of the class you want to test into the box next to “Class under test:” - the convention is to name your test something along the lines of “[name]Test”, where [name] is the name of the class you’re testing.

  15. JUnit Testing - 2 Put the tag “@Before” before any method you want run before every test Put the tag “@After” before any method you want run after every test To write a test, just put the tag “@Test” before a method If a test passes when an exception is thrown, use “@Test (expected = [exception name here])”

  16. JUnit Testing - 3 Within a test, use Assert to make sure that your test code is behaving as expected. For example, if your method adds two numbers and returns the result, you might test it with: Assert.assertEquals(3, addThese(5, -2)); or Assert.assertTrue(4 == addThese(2, 2));

  17. JUnit Testing - 4 To run a test class: - right-click on the class in the Package Explorer, hover over “Run An…” and select “JUnit Test”

More Related