Why we need [Unit] Testing or why they make our life easier ? There are many answer about this question.
- It allows you to check the expected behavior of the piece(s) of code you are testing, serving as a contract that it must satisfy.
- It also allows you to safely re-factor code without breaking the functionality (contract) of it.
- It allows you to make sure that bug fixes stay fixed by implementing a Unit test after correcting a bug.
- It may serve as as a way to write decoupled code (if you have testing in mind while writing your code). (SO — Unit testing in Java — what is it ?)
based on the above reasons, [Unit] Testing is very important. There are several unit tests namely Black box Testing and White box Testing. WHITE BOX TESTING is testing of a software solution’s internal structure, design, and coding. In this type of testing, the code is visible to the tester. BLACK BOX TESTING is defined as a testing technique in which functionality of the Application Under Test (AUT) is tested without looking at the internal code structure, implementation details and knowledge of internal paths of the software.
One of the Black Box Testing implementations in Java Swing with AssertJ Swing. AssertJ Swing is a Java library that provides a fluent interface for functional Swing UI testing. AssertJ Swing is based on JDK standard types assertions and can be used with either JUnit or TestNG. In this tutorial, we implement AssertJ Swing using Netbeans 11. Actually you can use your favorite IDE
Step 0: Prepration
using maven add dependency to your pom.xml
Step 1: Create Project and Add Library
Make a project on Netbeans with name TestSwing. Using File > New Project >Java with Maven > Java Application > Next > Project Name : TestSwingMaven > Create package with name com.ttm.testswingmaven > Finish. Add 2 files SimpleCopyApplication.java to Source Package and SimpleCopyApplicationTest.java to Test Package and add maven above.
Step 2: Write Code
Add this code to SimpleCopyApplication.java and try to running it.
then GUI will appear like this one
Step 3: Test GUI
Add this code into SimpleCopyApplicationTest.java
after add the code and test it
This article is based on several articles :