Difference between revisions of "Testing"

From DarkWiki
Jump to: navigation, search
(Terminology)
(Terminology)
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.
 +
 
 +
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, with communications between them. e.g. a UI, a JAR and a DB.
 
An '''environment''' is one or more systems, with communications between them. e.g. a UI, a JAR and a DB.

Revision as of 11:48, 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, 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.

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.

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.

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.