Skip to main content
1-Visitor
October 6, 2016
Question

JUnit tests with thingworx-ext-sdk

  • October 6, 2016
  • 5 replies
  • 3815 views

Greetings,

I'm trying to write some unit tests for my Java extensions and need to mock some classes.

I ran into this when trying to mock a Thing with certain properties.

Thing t = new Thing();

ThingProperty tp = t.addProperty(new PropertyDefinition("propertyName", "propertyDescription", BaseTypes.Boolean);

tp == null?

How could this be? Then i decompiled the thingworx-ext-sdk to find that most of the methods in the thingworx-ext-sdk are either simply empty (not implemented) or return null or some primitive value.

So, I thought that it would be useful to only use the thingworx-ext-sdk for compilation and the thingworx-sdk for testing, but i couldn't figure out how to make this work.

BTW, I'm using Eclipse as my IDE.

How do others unit tests their java extensions?

5 replies

5-Regular Member
October 7, 2016

Hi @Robert Taylor, Try replacing Thing t = new Thing(); with Thing t =ThingUtilities.findThing("NewThingName");

rtaylor-31-VisitorAuthor
1-Visitor
October 7, 2016

Hi Ankit,

Did you try it? It returns null because the thingworx-ext-sdk doesn't implement this method...that is the problem.

It simply returns null.

1-Visitor
October 7, 2016

Having similar problem when trying to make extension...

Complete example of Custom Authenticator

Also searching for improvments in dev flow of extension...

Do remote debugging support hotswap changed classes in Thingworx?

Hope this improves with some code examples...

1-Visitor
November 17, 2016

i think somewhere in the documentation you can find the information that were not supposed to run junit tests or make standalone applications.

you need to compile your project/ make an extension and then import it via composer.

only then you can debug your code

5-Regular Member
February 6, 2017

Just found some KCS documentation on this: https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS250862&lang=en_US

Full coverage unit tests are not possible in ThingWorx, but partial coverage is. If the logic that needs to be preserved is isolated from the statements that require context, then unit tests can be beneficial and functional. Hope this helps!