小编BON*_*BON的帖子

在xml中自动生成JUnit结果的最佳方法是什么?

我目前正在JUnit中编写一系列测试.我需要自动将结果导出为XML.我在阅读,最好的方法是扩展RunListener类并以这种方式编写XML.下面是我到目前为止所做的一些示例,但我正在努力解决如何提取已运行的每个测试的信息."描述"类似乎没有任何有用的get方法,我觉得我可能会以错误的方式解决这个问题.

有人可以协助如何从描述中获取有用的信息(例如,测试通过/失败,测试持续时间,测试名称等)或者就我实际应该做什么给我一些建议?

public class XmlListener extends RunListener {

    private final PrintStream fWriter;

    public XmlListener(JUnitSystem system) {
        this(system.out());
    }

    public XmlListener(PrintStream writer) {
        this.fWriter = writer;
    }

    @Override
    public void testRunStarted(Description description) {
        fWriter.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    }

    @Override
    public void testRunFinished(Result result) {
        fWriter.append("\t\t</suite>\n");
        fWriter.append("\t</suites>\n");
        fWriter.append("</result>\n");
        printHeader(result.getRunTime());
        printFailures(result);
        printFooter(result);

    }

    @Override
    public void testStarted(Description description) {
        fWriter.append("\t\t\t<case>\n");
        fWriter.append("\t\t\t\t<timestamp>"  + "</timestamp>\n");
        fWriter.append("\t\t\t\t<className>"  + "</className>\n");
        fWriter.append("\t\t\t\t<testName>"  + "</testName>\n");
    }

    @Override
    public void testFinished(Description description) {
        fWriter.append("\t\t\t\t<duration>"  + "</duration>\n");
        fWriter.append("\t\t\t</case>\n");
        Iterator it = description.getAnnotations().iterator(); …
Run Code Online (Sandbox Code Playgroud)

java xml junit

7
推荐指数
1
解决办法
2576
查看次数

如何从目标C中的NSDictionary中检索String?

我试图检索NSDictionary中的键的值.已使用类型字符串的键值对初始化字典.麻烦的是,我似乎无法通过调用objectForKey或valueForKey来检索值.

我能够遍历字典并打印键和值.

有人能指出我哪里出错吗?这是我的代码......

//Set up dictionary with options
keys = [NSArray arrayWithObjects:@"red", @"blue", nil];
values = [NSArray arrayWithObjects:@"1.7", @"2.8", nil];

conversionOptions = [NSDictionary dictionaryWithObject:values 
                                                forKey:keys];
Run Code Online (Sandbox Code Playgroud)

然后在选择器中的选择行上调用它

NSLog(@"... %@", [keys objectAtIndex:row]);       //prints out the key
NSString *theString = [keys objectAtIndex:row];   //save it as a string
NSLog(@"The string is... %@", theString);         //print it out to make sure im not going crazy

NSLog(@"the value is : %@",[conversionOptions objectForKey:theString]); // I just get NULL here
//NSLog(@"the value is : %@",[conversionOptions valueForKey:theString]); // This doesn't …
Run Code Online (Sandbox Code Playgroud)

arrays iphone objective-c

2
推荐指数
2
解决办法
1万
查看次数

标签 统计

arrays ×1

iphone ×1

java ×1

junit ×1

objective-c ×1

xml ×1