All Downloads are FREE. Search and download functionalities are using the official Maven repository.

reference.language.testing.html Maven / Gradle / Ivy




    
    Testing
    
    

    
    

    
    

    
    
    
    

    


Testing

Prompto promotes Test Driven Development (TDD) and automated testing. TDD is a development approach where you write tests before writing code. There are numerous benefits to it:

  • you gain a better understanding of the requirement before you start writing the code
  • you build a large number of tests which cover most if not all use cases

To encourage TDD, Prompto has a built-in testing framework, based on special methods called test methods.

Here is an example:

Test methods make it very easy to write tests before code, and even run them using the interpreter. The test will obviously fail until the correct code is implemented, which ensures that writing code actually does something: fix the test!

Test method structure

The structure of a test method is the following:

  • define <"test name"> as test method doing:
  • Prompto code being tested
  • and verifying:
  • Prompto verification code
where "test name" is a free text literal (the only restriction being that the name must be unique), and Prompto verification code is a list of one or more predicates i.e. boolean expressions.

Thanks to this structure, Prompto tests can check multiple predicates even if not all of them succeed, as in the below example:

Testing errors

Alternately, test methods can be used to check correct error handling. Here is an example:

Testing stored data

It is generally a bad idea to test against a permanent data store, because it means that the test success relies on the state of a data store which cannot be controlled by the test itself. To facilitate testing involving stored data, Prompto creates a fresh memory store before the test runs (the store is disposed immediately after execution of the test).

A reliable test involving stored data might look like the following:





© 2015 - 2025 Weber Informatics LLC | Privacy Policy