Difference between revisions of "Testing"

From DarkWiki
Jump to: navigation, search
(Terminology)
(Terminology)
 
(6 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
==Terminology==
 
==Terminology==
  
A ''system'' is one or more classes. (e.g. a JAR)
+
A '''function''' is a single piece of logical code.
  
An *environment* is one or more systems, with communications between them. e.g. a UI, a JAR and a DB.
+
A '''class''' is a group of one or more functions and, perhaps, state. e.g. a Java class with member variables.
  
*Unit tests* are short, fast and test a single class or function. They neither test nor rely on the behaviour of other pieces of code. These are used by developers to check the code they are writing.
+
A '''system''' is one or more classes. e.g. a JAR.
  
*Integration tests* are longer, and run within an environment. That environment may be full or partial. For example, a suite of tests can be run against an entire environment. However, more common is where testing of specific aspects is necessary. For example, testing the security of an API (rather than the code inside the API) will require a complex setup to be established, often relying on multiple systems.
+
An '''environment''' is one or more systems, often governed by a configuration and with communications between them. e.g. a UI, a JAR and a DB.
  
*Black box tests* do not test code behaviour, only the results. It's used to determine if something has changed, rather than if something is behaving correctly.
+
'''Unit tests''' are short, fast and test a single class or function. They neither test nor rely on the behaviour of other pieces of code. These are used by developers to check the code they are writing. i.e. ''they test the behaviour of functions''
 +
 
 +
'''Integration tests''' are longer, and run within an environment. That environment may be full or partial. For example, a suite of tests can be run against an entire environment. However, more common is where testing of specific aspects is necessary. For example, testing the security of an API (rather than the logic the API exposes) will require a complex setup to be established, often relying on multiple systems.
 +
 
 +
'''Black box tests''' (also known as '''system tests''') do not test code behaviour, only the results. It's used to determine if something has changed, rather than if something is behaving correctly.
  
 
==Mockito==
 
==Mockito==

Latest revision as of 11:53, 29 November 2019

Terminology

A function is a single piece of logical code.

A class is a group of one or more functions and, perhaps, state. e.g. a Java class with member variables.

A system is one or more classes. e.g. a JAR.

An environment is one or more systems, often governed by a configuration and with communications between them. e.g. a UI, a JAR and a DB.

Unit tests are short, fast and test a single class or function. They neither test nor rely on the behaviour of other pieces of code. These are used by developers to check the code they are writing. i.e. they test the behaviour of functions

Integration tests are longer, and run within an environment. That environment may be full or partial. For example, a suite of tests can be run against an entire environment. However, more common is where testing of specific aspects is necessary. For example, testing the security of an API (rather than the logic the API exposes) will require a complex setup to be established, often relying on multiple systems.

Black box tests (also known as system tests) do not test code behaviour, only the results. It's used to determine if something has changed, rather than if something is behaving correctly.

Mockito

Argument capture

To test to verify a certain value has been passed to a function, you need to use an ArgumentCaptor. This code is placed after the actual call under test.

    ...
    ArgumentCaptor<UserRecord> userRecordCapture = ArgumentCaptor.forClass(UserRecord.class);
    Mockito.verify(userRepository).saveUserAccount(userRecordCapture.capture());
    Assert.assertEquals("username", userRecordCapture.getValue().getName());

Cypress

Front end testing can be automated through Cypress.