cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

JUnit tests with thingworx-ext-sdk

rtaylor-3
1-Newbie

JUnit tests with thingworx-ext-sdk

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
ankigupta
5-Regular Member
(To:rtaylor-3)

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

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.

jgabriel
12-Amethyst
(To:rtaylor-3)

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...

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

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!

Top Tags