Solved

Unit testing and triggers

  • 29 November 2019
  • 1 reply
  • 53 views

Userlevel 2
Badge +5

I'm having difficulties unit testing certain concepts like a context. Let's say I'm having the following use case;

The purchase_order (PO) contains purchase_order_line's (POL). When the PO has the status ‘done’, the user or api cannot insert or update PO lines for that PO. I've disabled this using a trigger, i.e.

if exists ( 
select 1
from inserted i -- purchase_order_line
join purchase_order po
on po.purchase_order_id = i.purchase_order_id
where po.status = 'done'
)
begin

-- abort etc, cancel insert/update for purchase_order_line.

end

I have attached a layout and a context concepts for both the PO and POL's.

I want to unit test the behaviour for in example the context or layout of a purchase_order_line, that certain tasks / buttons are disabled. This can be done via unit test or via process tests.

If I do this via unit tests I have to create a Data set. When I do this and I execute the unit test, the data set creation fails: Due to the trigger i'm not able to both insert a purchase_order with status ‘done’ and a purchase_order_line.

Question is: How to deal with triggers in data sets? Can they be temporarily disabled?

An alternative is to create a process test, but that lack's the presence of data sets and should not replace the simplicity of an unit test.

icon

Best answer by Serhat Sahin 29 November 2019, 16:02

Hi René,

First of all, I'm glad to see that the unit test functionality is being used, especially in combination with mock data!

You have a strong case there, showing the exact problem we have faced using unit tests with mock data, while developing 2020.1.

The good news is, that this exact problem is already fixed in the 2020.1 development. This version will soon be released.

I hope this answers your question.

View original

1 reply

Userlevel 2
Badge +1

Hi René,

First of all, I'm glad to see that the unit test functionality is being used, especially in combination with mock data!

You have a strong case there, showing the exact problem we have faced using unit tests with mock data, while developing 2020.1.

The good news is, that this exact problem is already fixed in the 2020.1 development. This version will soon be released.

I hope this answers your question.

Reply