for testing my test codeunit I get a new error message:
And this is the code I am trying to test:
Thank you for your help
And what is the question?
The error looks like you're trying to change a field you don't want us to know the name of by giving it an wrong value. If you want to "catch" the error, then you need to use ASSERTERROR method before calling the statement.
So you mean in this way?!
Do I also need a commit?
No. Assume you didn't read the link to the ASSERTERROR method?
You must use it before the statement that gives the error en the code. The purpose of asserterrror is to catch the error, so that you later could check the GETLASTERRORTEXT against the expected error (what Assert.ExpectedError does for you).
If the event you expect to give you an error is when setting the value to the X-field for ItemCard, then you must use asserterror before this line.