Почему мой @BeforeClass метод не работает?

Если вы хотите напечатать вторую группу символов в строке, разделенной пробелом, вы можете разделить строку, используя пробел в качестве разделителя. Это даст вам список строк и доступ ко второму пункту списка.

Например:

print(article.get("data-variant-code").split(" ")[1])

result:  22222
41
задан Adeel Ansari 9 April 2009 в 07:27
поделиться

2 ответа

НЕ расширяйте TestCase и не используйте аннотации одновременно!
If you need to create a test suite with annotations, use the RunWith annotation like:

@RunWith(Suite.class)
@Suite.SuiteClasses({ MyTests.class, OtherTest.class })
public class AllTests {
    // empty
}


public class MyTests {  // no extends here
    @BeforeClass
    public static void setUpOnce() throws InterruptedException {
        ...
    @Test
    ...

(by convention: class names with uppercase letter)

64
ответ дан user85421 27 November 2019 в 00:32
поделиться

the method must be static and not directly call fail (otherwise the other methods won't be executed).

The following class shows all the standard JUnit 4 method types:

public class Sample {

    @BeforeClass
    public static void beforeClass() {
        System.out.println("@BeforeClass");
    }

    @Before
    public void before() {
        System.out.println("@Before");
    }

    @Test
    public void test() {
        System.out.println("@Test");
    }

    @After
    public void after() {
        System.out.println("@After");
    }

    @AfterClass
    public static void afterClass() {
        System.out.println("@AfterClass");
    }

}

and the ouput is (not surprisingly):

@BeforeClass
@Before
@Test
@After
@AfterClass
16
ответ дан Vladimir 27 November 2019 в 00:32
поделиться
Другие вопросы по тегам:

Похожие вопросы: