Skip to main content
Solved

Unit testing and triggers

  • November 29, 2019
  • 1 reply
  • 180 views

Forum|alt.badge.img+15

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.

Best answer by Serhat Sahin

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
Did this topic help you find an answer to your question?
This topic has been closed for replies.

1 reply

Serhat Sahin
Apprentice
Forum|alt.badge.img+1
  • Apprentice
  • 7 replies
  • Answer
  • November 29, 2019

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings