MENU

Fun & Interesting

JUnit 4 with IntelliJ: A quick introduction

Brian Fraser 146,411 9 years ago
Video Not Working? Fix It Now

Introductory video on using JUnit 4 in IntelliJ. For next video, check out: https://youtu.be/xHk9yGZ1z3k Hot Keys: - Alt-Insert: Generate code -- constructor, getter, test case - Alt-Enter: Quick-Fix something, such as create a test class, method, field. - Ctrl-Shift-F10: Set current run config. If done inside a test method, will run just that method. Otherwise runs whole class - Shift-F10: Re-run last run config. Steps: - Create new IntelliJ Java project - Create class under test: PetRock - Create test folder in project, and set as 'Test' folder File, Project Structure, Sources, select 'test' folder; click TESTS on top - Create test class from existing class Click class name; press Alt-Enter, Create Test Configure project for JUnit 4 - Write testGetName, run tests assertEquals - Run with CTRL+Shift+F10 to set what to run If in a test method, only runs that method If in test class, runs full class - Shift F10 = Re-run last "configuration" - Ctrl + Shift + T: Toggle between test and code-under-test - Create new test method for isHappy; run tests. - in JUnit class, Alt+Insert, Test Method - Alt + Enter: on non-existant methods to create. - use assertTrue, assertFalse

Comment