Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JUnit - Overview


May 15, 2021 jUnit


Table of contents


JUnit - Overview

The so-called unit test is to test whether the functionality of the application works as needed, and to ensure that the unit test generates pictures at the developer level. A unit test is a test of a single entity (class or method). Unit testing is an important part of every software company's efforts to improve product quality and meet customer needs.

Unit tests can be done in two ways

Manual testing Automated testing
Testing that manually executes test cases without the help of any tool is called manual testing.
- Time consuming and monotonous: Because test cases are executed by human resources, they are very slow and tedious.
- Significant investment in human resources: Because test cases require manual execution, more pilots are needed for manual testing.
- Low confidence: Low human test confidence is likely to result in a manual error that may have caused the test to run inaccurately.
- Non-program: Such programs cannot be written if you write tests that are complex and can get hidden information.
Using tool support and automated tools to execute use cases is called automated testing.
- Runs test cases faster than human resources when running test cases quickly and automaticly.
- Less investment in human resources: Test cases are executed by automated tools, so fewer pilots are required for automated testing.
- Higher confidence: Automated tests perform exactly the same operation each time they run.
- Programd: Experimenters can write complex tests to display hidden information.

What is JUnit?

JUnit is a unit testing framework for the Java programming language. JUnit has been an important development in test-driven development and is one of the unit testing frameworks that originated in JUnit collectively known as xUnit.

JUnit promotes the concept of "test first, code later" by emphasizing the creation of a piece of code for test data that can be tested before being applied. This approach is like "test a little, code a little, test a little, code a little..." and increases the programmer's output and program stability, reducing the pressure on the programmer and the time spent on scheduling errors.

Characteristics:

  • JUnit is an open resource framework for writing and running tests.
  • Provide comments to identify the test method.
  • Provide assertions to test the expected results.
  • Provide a test run to run the test.
  • JUnit testing allows you to write code faster and improve quality.
  • JUnit is elegant and simple. It's not that complicated, it takes less time.
  • JUnit tests run automatically and check their own results and provide immediate feedback. So there is no need to manually comb the report of test results.
  • JUnit tests can be organized into test suites that contain test cases and even other test suites.
  • JUnit shows progress in a bar. If it works well, it is green, and if it fails, it turns red.

What is a unit test case?

Unit test cases are part of the code that ensures that the other end of the code (method) works as expected. I n order to achieve the desired results quickly, a test framework is required. JUnit is the ideal unit testing framework for java programming languages.

A formally written unit test case is characterized by known inputs and expected outputs, that is, known before the test is executed. The input is known to be a prerequisite for testing, and the expected output requires a test postcondition.

Each requirement requires at least two unit test cases: a positive test and a negative test. If a requirement has sub-requirements, each sub-requirement must have at least two test cases, positive and negative.