简体   繁体   English

如何使用fitnesse测试或调用java方法?

[英]How to test or call a java method using fitnesse?

My requirement is to test or call a java method directly through fitnesse tool.我的需求是通过fitnesse工具直接测试或调用java方法。 I have used this tool for REST testing, but never for calling java methods directly.我已将此工具用于 REST 测试,但从未用于直接调用 java 方法。 Also googled , but no solution.也谷歌搜索,但没有解决方案。 Any help would be appreciated.任何帮助,将不胜感激。

Thanks谢谢

You need to write 'fixture' code which connects FitNesse to your Java classes.您需要编写将 FitNesse 连接到您的 Java 类的“夹具”代码。

You'll find details here: http://fitnesse.org/FitNesse.UserGuide您可以在此处找到详细信息: http : //fitnesse.org/FitNesse.UserGuide

For example, here's some information on one way to do that: http://fitnesse.org/FitNesse.UserGuide.FitLibraryUserGuide.DoFixture例如,这里有一些关于一种方法的信息: http : //fitnesse.org/FitNesse.UserGuide.FitLibraryUserGuide.DoFixture

I found the answer finally :我终于找到了答案:

To call any method of any Java class, just use Generic Fixture Eg.要调用任何 Java 类的任何方法,只需使用Generic Fixture Eg。

Java class : Java类:

package com.fitnesse.fixtures;


public class HelloWorld {

    public long getValue()
    {
        return 10;
    }

}

Fitnesse script to call the fore-mentioned java class :调用上述java类的Fitnesse脚本:

!| Generic Fixture | com.fitnesse.fixtures.HelloWorld|
|myvar=getValue||10|

So first line calls the default constructor of the Java class, and所以第一行调用 Java 类的默认构造函数,然后
second line calls the method getValue and saves it in myvar and also validates it with 10.第二行调用方法 getValue 并将其保存在 myvar 中,并使用 10 对其进行验证。

Using a script table you can do something like this:使用脚本表,您可以执行以下操作:

For static methods对于静态方法

|script   |java.util.UUID.randomUUID|
|$uuidVar=|to string                |
|check    |to string                | $uuidVar |

For non static methods对于非静态方法

|script             | MyClass       |constructor   |arguments|here|
|$classToString=    | to string     |
|check              | to string     |$classToString|
|$classReference=   | get fixture   |
|$storeMethodOutput=| my method name|

Any of the $ variables defined can be reference in later tables for just about whatever you need.任何定义的 $ 变量都可以在后面的表中引用,以用于您需要的任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM