比较一个JUnit @Test与同一类中另一个@Test的结果 [英] Comparing result of one JUnit @Test with another @Test in same class

查看:339
本文介绍了比较一个JUnit @Test与同一类中另一个@Test的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将一个JUnit测试的结果/输出与同一类中的另一个测试进行比较?

Is it possible to compare the result / output of one JUnit test to another test in same class?

下面是

Public class CompareResult {

@Before
{
open driver
}

@After
{
quit driver
}

@Test
{
Connect to 1st website
Enter data and calculate value
Store the value in Variable A
}


@Test
{
Connect to 2nd website
Enter data and calculate value
Store the value in Variable B
}

@Test
{
Compare A and B
}
}

当我显示变量A&的值时, B在第3个@Test中,它为NULL.我们不能在JUnit中的一个@Test中使用变量到另一个@Test吗?请告知,我是JUnit的新手.

When I display the value of variable A & B in 3rd @Test, it is NULL. Can we not use variable in one @Test to another @Test in JUnit? Please advise, I am new to JUnit.

推荐答案

为什么要进行两次测试?如果要比较这些值,则实际上确实有一个使用多种方法并且可能有多个断言的测试.而且如果helper1和helper2中没有任何断言,这将变得更加明显.没有断言的测试只是测试不会爆炸!

Why do they need to be two tests? If you are comparing the values, you really have one test with multiple methods and possibly multiple asserts. And if there aren't any asserts in helper1 and helper2, this becomes even more apparent. A test without an assert is just testing it doesn't blow up!

private helper1
{
    // Connect to 1st website
    // Enter data and calculate value
    // Store the value in Variable A
}


private helper2
{
    // Connect to 2nd website
    // Enter data and calculate value
    // Store the value in Variable B
}

@Test actualTest
{
    // Compare A and B with assertion
}

这篇关于比较一个JUnit @Test与同一类中另一个@Test的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆