You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mapstruct-users
Hi,
As I am using Mapstruct for my project, I feel the need for a Unit Test generation just like how Mapstruct has Mapping Code generation. We should have a way of generating a Unit test for the class that was just mapped by Mapstruct. We can just do Asserts on the source and target fields that we mapped. The user would obviously have to set the values for the objects, but apart from that he should be able to run the code as is.
Best
Pooja
Sjaak Derksen
unread,
Nov 14, 2016, 3:44:34 PM11/14/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mapstruct-users
Hi Pooja,
You might want to try assertReflectionEquals from: http://www.unitils.org/tutorial-reflectionassert.html in combination with reverse mapping. So: prepare an object(graph). Map it with MapStruct. Do a reverse map with MapStruct and run assertReflectionEquals.
I use this roundtrip mapping all the time for mappings from JAXB to DTO and vice versa.
Best regards,
Sjaak
Pooja Venkatram
unread,
Nov 21, 2016, 7:32:32 PM11/21/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mapstruct-users
Hi Sjaak,
Thank you so much for your response. I will take a look into this. the only problem with reverse mapping is that some of the objects are not reverse mapping compatible(like immutable fields). Do you deal with any such fields or are all your fields reverse mappable?
Best
Pooja
Sjaak Derksen
unread,
Dec 5, 2016, 2:56:10 PM12/5/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mapstruct-users
Hi Pooja,
Sorry for my late response. For immutable fields I don't have a direct solution. You could however make the problem a bit smaller by setting them manual before you run reflectionAssertEquals and test those remaining ones with regular asserts on the target side.