Java: JUnit 4 Example

(Last Updated On: )

In this tutorial I will show you how to use JUnit 4 into your application. The next tutorial I will use this class with PowerMock.

Build Path

Ensure you have added JUnit 4 to your build path and that you are using Java 8.

Imports

  1. import org.junit.Before;
  2. import org.junit.Test;

Test Class

  1. package ca.gaudreault.mytestapp;
  2.  
  3. import org.junit.Before;
  4. import org.junit.Test;
  5.  
  6. public class AppTest {
  7. @Before
  8. public void setup() {
  9. }
  10.  
  11. @Test
  12. public void myTest() {
  13. }
  14. }

This was a very basic example of writing a unit test with JUnit 4. In future example I will build on this with PowerMock.

One thought on “Java: JUnit 4 Example”

Comments are closed.