有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Android Studio中的java Junit

运行junit时,我在获取“PASS”消息时遇到问题。当我跑的时候什么也没发生。系统。out也不会输出。我真的不确定我做错了什么。有什么想法吗

完整测试套件。爪哇

import 安卓.test.suitebuilder.TestSuiteBuilder;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.util.ArrayList;
import static org.junit.Assert.*;
import cen4910.ucf.edu.aaa_安卓_auto.pojo.Driver;

public class FullTestSuite {
    public static void main(String [] args)
    {
        DriverTest.test();
        /*
        Driver testDriver = new Driver("password", "john", "smith", "test@gmail.com");
        AssertNotNull(testDriver);
    }
}

驾驶员测试。爪哇

import pojo.Driver;
import static org.junit.Assert.*;

public class DriverTest {
    public static void test() {
        Driver testDriver = new Driver("password", "john", "smith", "test@gmail.com");
        assertNotNull(testDriver);
        if (testDriver == null) {
            System.out.println("Success!");
        }
        else {
            System.out.println("Failure!");
        }
    }
}

共 (1) 个答案

  1. # 1 楼答案

    我还没有使用Android Studio,但在您的代码中没有看到JUnit测试用例

    尝试用@Test注释测试用例。启动JUnit测试不需要main方法

    也许你应该阅读JUnit教程,了解如何在你最喜欢的IDE中运行JUnit测试的基本知识

    import pojo.Driver;
    import static org.junit.Assert.*;
    import org.junit.Test;
    
    public class DriverTest {
    
        @Test
        public void test() {
            Driver testDriver = new Driver("password", "john", "smith", "test@gmail.com");
            assertNotNull(testDriver);
        }
    }