Unit test for Service

Hi,

Any idea on how to write unit test classes for services, a custom service is I am looking for. I tried the standard approach of SysTestCase but it does not allow to call the service class because of SysEntryPointAttribute.

Can you please describe your problem in detail? What do you mean by “it does not allow to call the service class”? Do you get an error? What does the error message says and when exactly do you get it? How does your code look like?
The fact that a method has some attributes doesn’t have any effect when you’re calling the method directly, so you’re probably doing something else…

Hi,
This is how I created the test class and its methods:

[SysTestTargetAttribute(“CustomServiceClass”,UtilElementType::Service)]
class CustomServiceClassTest extends SysTestCase
{
CustomServiceClass CustomServiceClass;
}

public void setUp()
{
// setup data here

super();
}

[SysTestMethodAttribute]
void testConfirm()
{
CustomServiceClassTest = new CustomServiceClassTest ();
this.assertEquals(output, output returned by service call);
}

Here because service has [SysEntryPointAttribute], not able to call service from above assert equals.

I still don’t know what you mean by “not able to call service”. Could you describe the problem, please?

Also, why did you hide the most important part of your code, i.e. the method call that doesn’t work? And why you’re creating another instance of the test class inside your tests? Didn’t you mean CustomServiceClass instead of CustomServiceClassTest?

By the way, you’re testing a class, therefore your SysTestTargetAttribute should look like this:

[SysTestTargetAttribute(classStr(CustomServiceClass), UtilElementType::Class)]

Yes you are right I meant CustomServiceClass not CustomServiceClass Test . Even when I do

[SysTestTargetAttribute(classStr(CustomServiceClass), UtilElementType::Class)] I get the below error:

Can you please give us a sample code that we can copy and run? What you gave us before clearly wasn’t correct (as it wasn’t even using the right class).

By the way, your screenshot isn’t very useful if you black out the most important part. Please tell us what’s there.