Test a workflow of your app
A workflow test signs in as one of your users, fills in your forms, presses your buttons, and then
reads the rows that the application stored. You write it in a .mtdtest file. You need no
JavaScript, no selectors and no SQL.
This guide uses the city-news example, a newspaper in which an author writes a draft and an editor
publishes it. The files are in dsl/examples/city-news/. The syntax is in
Workflow tests.
1. Give the tests some people to log in as
Section titled “1. Give the tests some people to log in as”A user that has a profile is bound to a row of the profile table. The row must exist before the first
request, so it comes from the seed of the application. city-news binds its person profile to the
people table and ships three people:
id,first_name,last_name,email,bio1,Wanda,Writer,writer@news.example,Reports on the town council.2,Edgar,Editor,editor@news.example,Edits the desk.3,Alma,Admin,admin@news.example,Editor-in-chief.The seed is read like install -seed. Read Load demo data and bind logins to records
for the rules. An application whose users have no profile needs no seed. A test makes any other row
through the pages of the application, like a person would.
2. Write the suite and its users
Section titled “2. Write the suite and its users”Create tests/editorial.mtdtest in the application directory. A file holds one suite:
suite "Editorial workflow" { seed: seed clock: 2026-09-30T10:00:00Z locale: en
user writer { email: "writer@news.example" roles: author profile person = 1 }
user editor { email: "editor@news.example" roles: editor profile person = 2 }clock: fixes the time of every request, so a test gives the same answer on every day. Each user
is a login with the roles that you list. The runner creates the logins for you, and every one has the
password workflow-test-password.
3. Write a test as one person after another
Section titled “3. Write a test as one person after another”A test is a list of steps. It starts with as, and each page you open is followed by what the engine
answered:
test "An editor publishes an author's draft" { as writer open newsroom_post_new expect ok fill posts { title: "Club news" body: "Training starts on Monday." } submit expect savedopen names a page, as you wrote it in the page declaration. expect ok says that the page came
back. fill names the form by its table and sets fields by the text a person types. expect saved
says that the save worked.
The test does not stop at the answer. It reads the row that the save wrote:
// The form sets the author and the engine derives the address and the // starting state; the hook counts the words. expect row posts where title = "Club news" { slug: "club-news" status: draft author: 1 published_at: empty words: 4 } as articleexpect row finds exactly one row by its condition and compares the columns that you list. The row
is read straight from the database. A rule that hides the row from a user does not hide it from
the test. as article gives the row a name that the next steps can use:
as editor open newsroom_post(article) expect ok run transition publish expect saved expect row posts where id = article.id { status: published published_at: 2026-09-30T10:00:00Z }open newsroom_post(article) opens the page of that row. published_at is the clock: of the suite.
A bound name is also a value. The shift roster adds a volunteer and then assigns the new volunteer to the
welcome desk. The test bound the shift earlier, by its title
(expect row shifts where title = "Open welcome desk" as welcome). It writes neither id. It uses the names:
expect row volunteers where email = "lena@example.test" { first_name: "Lena" active: true } as lena
open assignment.new expect ok fill assignments { volunteer: lena.id shift: welcome.id status: "confirmed" }lena.id is the id of the row that lena names. If the seed gets a fifth volunteer, the test still
works. A block of expect row takes the same words, for example post: article.id. See
Use a bound row as a value.
4. Test that an action is refused
Section titled “4. Test that an action is refused”A test of access has two parts: the answer, and proof that nothing changed. The author may not publish their own draft:
open newsroom_post(story) expect ok run transition publish expect refused
expect row posts where id = story.id { status: draft published_at: empty } expect none posts where title = "My own story" and status = publishedThe engine does not draw a Publish button for an author. The runner sends the request that the button would send, and the test notes say so. The engine answers 403. A note is not a failure:
ok An author cannot publish their own draft (49 ms) note: city-news/tests/editorial.mtdtest:84:5: run transition publish: page newsroom_post drew no button for transition publish to writer; sent the request the button would sendOther outcomes cover the other denials. expect missing is a row that the user may not see,
expect login is a visitor who must sign in, and expect invalid title is a form that marks the
title control. Check the outcome of a step
lists all nine.
Some refusals have no word. In the time tracking example, the entry page draws one form to a consultant. The
form with the employee control is backoffice’s, and the page does not draw it to a consultant. Write
anyway to send the save to it, and expect 400 for the engine’s answer. A 400 is the answer for a form
that the user is not admitted to, and the same answer as for a number of a form that does not exist, so the
test learns nothing that a visitor could not learn. Then show that nothing was stored:
fill time_entries in region anybodys_time anyway { employee: max project: reporting minutes: "45" description: "Forged booking" } submit expect 400 expect none time_entries where description = "Forged booking"A number is only for an answer that no word names: a 4xx other than 403, 404 and 410. Read Check an answer that no word names.
A public page of an application with several languages has a second address for each language. A suite
with locale: de that opens such a page is sent to the German address, and the runner follows that one
redirect, as a browser does, and says so in a note under the test. Write the German text that the page shows:
as anonymous open start expect ok expect shows "Events des Königreichs" expect shows "Events auf Ihrem Gerät"A person who clicks a link on a page of the application is not a first visit. The engine serves the click at
the address that it asked for, in the language of the application. Write the page that holds the link after
from. The suite is locale: de and still gets the English page:
open start from subscribe(mine) expect ok expect shows "Upcoming events" in list of events expect hides "Bevorstehende Events" expect hides "Events des Königreichs"When the page after from is on the screen, the runner also checks that the page draws the link. The front
page draws a button “Create my calendar”, so a visitor can click it:
open subscribe.new from start expect ok expect shows "Save calendar" expect hides "Kalender speichern"A click on a link that the page does not draw fails before any request. Open the page that holds the link first, and the test checks the link. When nothing is on the screen, as after a save, the step sends the request of a click and reads no link.
The next open start, with no from, is the first visit and gets the German page. See
Click a link.
Only expect invalid leaves the form on the screen, so a corrected fill can follow it. Every other
outcome finishes the page, as a save does: after rejected, refused or saved, open the page again
before the next fill, submit or run. A second run on the same open is a validation error, not
a 403.
5. Test that a rule stops a step
Section titled “5. Test that a rule stops a step”Some rules belong to no control: a check over two columns, a unique over several, a deny when, a
require or a hook. The engine answers 200, draws the page again with the sentence of the rule, and
marks no control. expect rejected is the word for this answer. The room booking has
check ends_at is empty or ends_at > starts_at, so a booking that ends before it starts is rejected:
submit expect rejected "end must be after the start" expect none bookings where title = "Backwards"The text is a piece of the message and is optional. The case counts. A transition that a rule
stops is also rejected. The newsroom does not schedule a post that has no publication time:
open newsroom_post(soon) expect ok run transition schedule expect rejected "needs a publication time" expect row posts where id = soon.id { status: draft }A run never ends in ok: a move that happened is saved, and a move that a rule stopped is
rejected. The validator refuses expect ok after a run before it sends a request. Assert the rows
too, as in the previous section.
Send a save that the page did not draw
Section titled “Send a save that the page did not draw”A deny when of a form can already hold when the page opens. The engine then draws the sentence of the
rule and no form. In the sports club, an event with one place is full after one signup. The page still
opens with ok, and a plain fill event_signups fails because there is no form. Write anyway to send
the save that the form would have sent. The engine must refuse it:
open public_signup(one) expect ok expect count event_signups where event = one.id = 1
fill event_signups anyway { guest_name: "Jonas Kern" guest_email: "jonas@example.test" } submit expect rejected "fully booked" expect none event_signups where guest_email = "jonas@example.test"The test notes record the step, as they do for a transition button that the page did not draw. The note is not a failure. Name every control that the save needs, because the runner has no drawn form to take a value from. See Send a save that the page did not draw.
Send a delete that the page did not draw
Section titled “Send a delete that the page did not draw”The delete button is another thing that a page draws only for some users. When the form is drawn and only
the button is missing, a plain submit delete already sends the request of the button, and the engine
answers 403. A page can also draw no form of the region to a user. The time entry page draws one form to
a consultant and another to backoffice. Write anyway to send the delete that the form of backoffice would
send, as a consultant. The engine must refuse it, and the row must stay:
as consultant expect row time_entries where employee = 4 and days_since(work_date) = 0 and minutes = 120 as mine open entry(mine) expect ok submit delete in region anybodys_time anyway expect 400 expect row time_entries where id = mine.id { minutes: 120 }The answer is 400, because the engine treats a region that the role does not admit as a region that is not
there. When a deny when holds, the answer is rejected with its sentence. A plain submit delete for a
form that the page did not draw fails, and the failure names anyway. See
Send a delete that the page did not draw.
Copy a row as a template
Section titled “Copy a row as a template”A form that lists duplicate in its actions: has a “Copy as template” link. The shift roster uses it to
plan next year’s shifts. open shift.new copying welcome makes the request that the link makes. welcome
is a shift that an earlier step bound. The engine reads that shift into the create form and leaves the
dates empty (clear: starts_at, ends_at):
open shift.new copying welcome expect ok submit expect invalid starts_at
fill shifts { starts_at: "2100-12-01 09:00" ends_at: "2100-12-01 12:00" } submit as next_year expect savedThen assert the copy and the shift that you copied. Who may copy is a question for the engine, so test
it too. A volunteer is refused, and a visitor goes to the login:
as helper expect row shifts where title = "Open welcome desk" as welcome open shift.new copying welcome expect refused
as anonymous open shift.new copying welcome expect login expect count shifts = 3See Copy a row as a template for what a copy carries and what the engine answers for a row that the user may not see.
Fill one of two forms
Section titled “Fill one of two forms”The time entry page of the time tracking example has two forms of time_entries. A consultant logs their
own time with the first. Backoffice logs the time of anybody with the second:
form of time_entries { test_id: own_time access: consultant, manager fields: work_date, project, minutes, billable, description set employee = :user.employee_id}A fill is for the form that the page draws to the user who acts. The consultant is drawn the first form,
so fill time_entries { … } needs no more:
as consultant expect row projects where code = "ACM-ERP" as erp
open entry.new expect ok fill time_entries { project: erp minutes: "90" description: "Sprint planning" } submit expect savedWhen the page draws two forms of one table to the same user, the check before the first request refuses the
fill and lists the forms. Give each form a test_id: and write it after in region. You can write
in region also when one form is drawn. This is the second form, with the control that the consultant’s
form does not have:
open entry.new expect ok fill time_entries in region anybodys_time { employee: carla project: reporting work_date: "2026-09-28" minutes: "45" description: "Booked by backoffice" } submit expect savedWrite anyway after the region (fill … in region <test_id> anyway { … }) to send the save of a form that
the page did not draw to this user. Without it, a form that the user is not admitted to is refused before the
first request. See Choose the form of a fill.
A delete has no fields, so it names its form in the submit. Some logins are drawn both forms: the suite
of the example has a backoffice login that is also a consultant. For that login a bare submit delete is
refused, and the repair lists the ids. This delete goes through the form of their own time:
open entry(mine) expect ok submit delete in region own_time expect deletedOnly a delete takes in region. See
Choose the form of a delete.
Save a sheet
Section titled “Save a sheet”A sheet region is a grid. A person changes cells in many rows and presses one button, and the engine writes
all the rows or none. A fill cannot do this, because the grid has no form. In the shift roster, a
coordinator edits assignments in the roster grid. Name the rows, which an earlier expect row … as <name>
bound, and the cells to change. Then submit:
open roster expect ok sheet assignments { row sam_welcome { status: "confirmed" } row alex_welcome { status: "confirmed" } } submit expect invalid alex_welcome.status "all the volunteers it needs"The welcome desk needs two volunteers and has one. Sam alone fits, and Sam and Alex together do not. The engine refuses the whole save and marks the cell of the second row. A refused save writes nothing, so show that Sam’s row did not change either:
expect row assignments where id = sam_welcome.id { status: waitlist } expect row assignments where id = alex_welcome.id { status: cancelled }The names in expect invalid are <row>.<column>. A rule without a cell gives a sentence of the save, which
expect rejected "<text>" reads. To prove that a sheet cannot reach a row that it does not list, name the row
and write anyway. The same word sends a save to a sheet that the page did not draw to this user, and the
answer is expect 400. See
Save a sheet.
6. Test what a user is shown
Section titled “6. Test what a user is shown”expect row reads the database, so it also sees a row that a page does not show. It cannot say what a
reader sees. Three other assertions read the page that the engine drew for the user: expect shows,
expect hides and expect rows.
The front page of the newspaper lists published posts only. A draft is stored, and a visitor must not see it. Open the front page as a visitor, and check the draft in both ways:
as anonymous open post(article) expect missing open start expect ok expect rows in region front_posts = 0 expect hides "Club news" in region front_posts expect count posts where title = "Club news" = 1expect hides says that the text is not in the list of the front page. expect count says that the post is
stored. Both are true, and each one answers a different question. The list has no label, so the page
source gives it a name for tests, test_id: front_posts. See
Name a region for a test below.
A hides can hold for the wrong reason. If the front page listed nothing at all, every text would be
absent. Pair it with a shows or a rows that must hold on the same page. In the same test, the editor
publishes the post and the front page lists it:
as anonymous open post(article) expect ok open start expect ok expect rows in region front_posts = 1 expect shows "Club news" in region front_postsA region that has a label can be read alone, and its rows can be counted. The Kingshot calendar lists the events of a calendar, without the categories that its owner hid. Two events are stored, in two categories. The owner of the first calendar hid one category:
open subscribe(quiet) expect ok expect rows in list of events = 1 expect shows "Bear 1" in list of events expect hides "Raid 1" in list of eventsA region is written as the page declares it: the kind, of, and the table. expect rows counts the rows
that the page drew. The test then opens the calendar of a second visitor, who hid nothing, and expects
two rows. That second calendar shows that the first result is the filter and not an empty page.
Name a region for a test
Section titled “Name a region for a test”The kind and the table name a region only when the page has one such region and the region has a label.
For any other region, give it a test_id: in the page source. The engine writes it into the page as
data-testid. A test then writes region and the id. The public availability page of the hall booking
has a list with no label. This is the source:
report of bookings where status = confirmed and starts_at >= now { test_id: availability_list columns: starts_at, ends_at, title, room, resource}The test counts the rows of the list and reads the text in it. Contact data is never drawn there:
open availability expect ok expect rows in region availability_list = 1 expect shows "Winter concert" in region availability_list expect shows "Main room" in region availability_list expect hides "Anna Miller" in region availability_listA test_id is one name of lower-case letters, digits and _, at most 40 characters, and it is unique on its
page. It is never one of the region kind words, such as list. The test_id does not change who may see the
region. If the engine does not draw the region for the user, the id is not in the page and the step fails.
See Regions: test_id.
Some rules for these assertions:
- The text is part of the page text, and the case counts. Write a name or a number from your data and not a label that you may reword.
- A report shows one page of rows, 25 by default.
expect rowscounts the rows of that page. - A region without a label, and two regions of one kind and table, are named by their
test_id. - A page assertion needs a page on the screen. After
savedorrefused, open the page again. - If the engine did not draw the region for the user, the step fails, also for
hides.
When an assertion fails, the failure prints the rows or the text that the page showed. See Check what the page shows.
Test the order of a list
Section titled “Test the order of a list”A sort: is a promise about order, and expect rows counts rows and cannot check it. The front page of the
newspaper has sort: published_at desc. The test writes a time on two drafts, publishes three posts, and
reads the front page as a visitor:
as anonymous open start expect ok expect rows in region front_posts = 3 expect rows in region front_posts in order "Library opens", "Market day", "Budget decided"The texts must appear in this order in the region. They do not need to be next to each other. If you change
the sort: to published_at, the test fails at "Market day", because the region shows the oldest post
first, and the failure prints the order that the region shows. Use a part of the text that is specific to
one row. See Check the order of the texts in a region.
Test a page that is not ready
Section titled “Test a page that is not ready”Some pages cannot be built until the first row of the app scope exists. The school app has no page to read
before the first term. A new school, with a subject in the seed and no term, answers 503 for the page of
courses. The word for it is unavailable:
as head open courses expect unavailable expect shows "This app needs the first Term before this page can show anything." expect shows "Create the first Term"The page is the engine’s own, so you read its text with expect shows. It does not hold the regions of
your page. A user who may not create the term gets another sentence, and a visitor is sent to the login page.
The test then creates the school year and the term through their own pages and opens the page again. It is
ok now. See Check a page that is not ready.
Test a page of another term or season
Section titled “Test a page of another term or season”Some applications keep an app-wide scope: the school app has a term, and the feature gallery has a
season. A person chooses the scope with the selector in the page header, and the engine keeps the choice
for that person. A test that does not choose sees the default scope, which is the current term. The school
has a second term in its seed. The course of that term is in no list, and its page is a 404, until a person
chooses the term. First check the current term. Then choose the earlier term and open the list again:
open courses expect ok expect rows in report of courses = 1 expect shows "8b M" in report of courses expect hides "7b M" in report of courses open course(old_course) expect missing open assignment(old_essay) expect missing open assessment(old_test) expect missing
open courses expect ok choose term = last_term expect savedlast_term is a name that an earlier expect row terms where name = "2025/26-2" as last_term bound. The
selector is in the page that is on screen, so choose follows an open that ended in expect ok. The
engine answers with a 303 back to the page, which is saved. The step does not read that page. Open the
page again to see what the choice did:
open course(old_course) expect ok expect shows "Last term's essay" in list of assignments expect shows "Last term's test" in report of assessments open assignment(old_essay) expect ok open assessment(old_test) expect ok expect shows "Oezdemir" in report of marksThe choice stays for the user who made it. Another user, and the next test, still read the current term. See Choose a scope.
Test what a new session sees
Section titled “Test what a new session sees”The choice of a scope belongs to the session. as reuter a second time goes back to the session that
Reuter holds, and the choice is still there. sign out ends the session on the server. The next as reuter
is a new sign-in, and the scope is at its default: again. Choose the earlier term, then sign out and in:
sign out as reuter open courses expect ok expect rows in report of courses = 1 expect shows "8b M" in report of courses expect hides "7b M" in report of coursessign out has no outcome, and it leaves no page on screen: open a page after it. It needs a user who is
signed in, and the check refuses it for as anonymous. See Sign out.
7. Run the tests
Section titled “7. Run the tests”From the directory that holds the application:
matterdata test .The command validates every file before it makes a request. A misspelled page, field, role or
transition is reported with file:line:column and a repair, and no test runs. A run prints one line
for each test and exits with status 1 when a test fails.
8. Read a failure
Section titled “8. Read a failure”Change status: draft to status: review in the test above and run it again:
suite "Editorial workflow" (city-news/tests/editorial.mtdtest) FAIL An author cannot publish their own draft (20 ms) city-news/tests/editorial.mtdtest:87:5: expect row posts row 1 of table posts, found where id = story.id, holds other values column status: expected review, actual draft (city-news/tests/editorial.mtdtest:88:15) note: city-news/tests/editorial.mtdtest:84:5: run transition publish: page newsroom_post drew no button for transition publish to writer; sent the request the button would send
FAIL 1 test, 0 passed, 1 failed, 8 not selected in 67msThe first position is the step that failed. The position in brackets is the value that you wrote. The failure lists every column that differs, not only the first. When the outcome is wrong, the failure shows the expected and the actual word, the status, and the message that the page rendered.
Use -run to run one test while you fix it. The pattern is a regular expression for
<suite name>/<test name>:
matterdata test . -run "cannot publish"9. Look at a failed tenant
Section titled “9. Look at a failed tenant”-keep keeps the directory of each failed test and prints its path. -serve with -keep also serves
the tenant until you press Ctrl-C:
matterdata test . -run "cannot publish" -keep -serveThe command prints an address of the form http://workflow.localhost:<port>/, the email of each user
and the test password. Open the address in a browser, sign in and look at the state that the test left. Press
Ctrl-C to stop the server. The directory stays on disk. Delete it when you are done.
10. Run the tests in your build
Section titled “10. Run the tests in your build”matterdata test exits with status 1 for a failure, a file that does not parse and a suite that
cannot start. Run it in the same job that runs matterdata validate. On 2026-10-01 the example suites of five tests ran in
64 to 82 ms on an Apple M3 Pro, and all 63 tests of the 11 example suites ran in 1.1 s. The suites have
grown since then. See the measurement file named in
How workflow tests run.
Check what a test does not cover
Section titled “Check what a test does not cover”- A
fillis for the form that the page draws to the user who acts. When the page draws two forms of one table to that user, give the forms atest_id:and name one:fill <table> in region <test_id> { … }. Asubmitwith nofillbefore it takes the form that the page draws to the user. When that is two forms, a delete names one:submit delete in region <test_id>. - A page assertion reads the text of the page. It does not read an export, the grid of a sheet or a chart. An order is read in one region.
- Only a 503 has an outcome word,
unavailable. A test cannot expect another 5xx. - A form that the page did not draw for a role (a region
access:) is answered 400 whenanywaysends it. No outcome word fits 400, so writeexpect 400. - A test cannot read the value of a one-line control. After a copy, save the form and assert the stored row.
- A
sheetstep saves cells of rows that exist. It does not add or delete rows of the grid, and it cannot show a stamp that went stale between the page and the save. The runner does not run the JavaScript of the grid. - A test can attach a file with
file "files/…", remove a stored file withremove fileand fetch a stored file withdownload. A file that a page routed by a token draws is fetched withdownload <name>.<field> with token <name>.<column>.downloaddoes not read the headers of the response. See Attach a file and Remove a stored file. - Mail and jobs are not driven yet. See Project status.
- Workflow tests, the complete syntax
- How workflow tests run, for the reasons behind the rules