JUnit 4 with IntelliJ: A quick introduction
Brian Fraser Brian Fraser
28.7K subscribers
145,807 views
0

 Published On Jun 20, 2016

Introductory video on using JUnit 4 in IntelliJ.
For next video, check out:    • JUnit 4 with IntelliJ: Exceptions, Ig...  

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

show more

Share/Embed