【java – 测试可完成的未来总是通过】教程文章相关的互联网学习教程文章

阿里JAVA实习生入职测试题(2019最新)【代码】【图】

根据我的理解和搜集的资料,尽可能清晰完整的回答(逐步完善,持续更新) 1、String类为什么是final的 首先分析String的源码:public final class Stringimplements java.io.Serializable, Comparable<String>, CharSequence {/** The value is used for character storage. */private final char value[]; 类被final关键字限定,说明它不可以被继承,没有子类。即持有一个String对象的引用,它必然是String类,而不会是其他的类。...

java – 将gradle更新为2.10,现在travis无法找到我的测试【代码】

我想这是travis-ci的支持?我是从他们的网站发送到这里的.我想我应该在这里问这个问题. 所以我将Google Analytics添加到我的应用中,为此,我必须将gradle更新为版本2.10以获取其插件.完成后,所有travis-ci都运行了我的构建,但是每次构建时都会出现以下错误:com.android.builder.testing.ConnectedDevice > No tests found.[test(AVD) - 5.0.2] FAILED当我使用gradle2.2.1时,这不是问题.所有. 要更新,我在gradle / wrapper / gradle...

java – 是否可以在外部探查器下运行JMH基准测试?

我现在正在打猎.为了衡量吞吐量,并强制我们不退步,我正在使用精彩的JMH. 当我遇到一些缓慢的东西时,我想开始分析以查看发生了什么,根据JMH的作者this link写道:While JMH profilers can provide the aid in analyzing, I don’t think theyare the substitute for proper profiling. E.g. the “stack” profiler isgood to glance over the profiles, but not for the serious work. Run the workload for longer, and attach y...

java – 使用noparameters分支的void方法的测试用例【代码】

我有没有参数的String方法,但它有if条件.public String id1() {Random random=new Random();int i=random.nextInt();if(i<0){i=-(i);}if(i<1000)i=i+1000;while(i>9999){i=i/10;}return i+""; }在这种情况下如何编写Junit测试用例?解决方法:您可以将逻辑分解为自己的方法:public String id1(int i) {if(i<0){i=-(i);}if(i<1000)i=i+1000;while(i>9999){i=i/10;}return i+""; }然后通过传递一个随机int来改变你调用id1的方式:id1...

java – 如何使用Mockito测试要测试的类中的throws子句【代码】

该流程从Controller.callMethod()开始.它调用抛出MyException的方法. MyException由Controller中编写的Exception处理程序处理:public class Controller{public Response callMethod() throws MyException {ClassToTest classToTest = new ClassToTest();return(classToTest.method());}@ExceptionHandler(MyException.class) public @ResponseBody Response myException(HttpServletRequest req,HttpServletResponse res, MyExcep...

java – 编写Junit测试以覆盖异常和catch块【代码】

我已经为以下函数编写了Junit测试用例.当检查JACOCO测试覆盖率时.它显示只有try块被测试用例覆盖.我是编写测试用例的新手.如何在测试用例中涵盖异常和catch块 这是一种方法public static List<Student> readCsvFile(String fileName){BufferedReader fileReader = null;//logic to read file } catch (Exception e) {System.out.println("Error in CsvFileReader !!!");e.printStackTrace();} finally{try{fileReader.close();...

java – 在Kotlin中编写单元测试,共享变量?【代码】

我正在尝试在Kotlin中创建一些功能测试,以使用Rest Assured库向Cart Java服务发出请求. 由于我希望测试在程序上表现,我希望我可以存储第一个A??PI请求的结果并将其传递给下一个单元测试. 即 createCartTest() – > cartId – > getCartForWebsiteTest(cartId)class CartTest : RestAssuredSupport {val port = 8080val url = "http://localhost:"val cartId = null/*** Create a cart object*/@Test fun createCartTest() {given(...

java – 有关JUnit测试的字段的访问权限【代码】

假设我有一个以链表样式实现堆栈的类:public class Stack {private StackNode base;public void push(Object item) {if (base == null) {base = new StackNode(item);}// remaining implementation not shown} }和它的JUnit测试类:public class TestStack {@Testpublic void testPush() {Stack st = new Stack();st.push(new Integer(3)); assertEquals((Integer)st.base.getContents(), new Integer(3)); //Error!// other test...

基于Java+Selenium的WebUI自动化测试框架(七)--IE浏览器的设置【图】

在上一篇我们讲了关于WebDriver的版本,浏览器初始化,以及下载的设定。在设置IE浏览器进行WebDriver的测试时,通常会遇见以下几种错误: 1.没有关闭IE浏览器的保护模式。 当运行测试用例后出现类似以下内容的错误: Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Pro...

java – 在测试中使用@MockBean强制重新加载Application Context【代码】

我在Spring Framework上运行了几个集成测试,扩展了名为BaseITCase的基类.像这样:@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {AppCacheConfiguration.class, TestConfiguration.class}, loader = SpringBootContextLoader.class) @Transactional @WebMvcTest public abstract class BaseITCase{...} ... public class UserControllerTest extends BaseITCase {...}问题是其中一个测试有几个声明:在...

java – 服务层测试:使用dbUnit时是否仍然是单元测试而不是模拟本机Spring域层?【代码】

我有一个服务层和一个域层.我使用普通的本机Spring存储库作为域层,在我的测试设置中,我用dbunit模拟数据库.@Repository public interface ExampleRepository extends PagingAndSortingRepository<ExampleEntity, Long>, JpaSpecificationExecutor<ExampleEntity> { }当然,我将假设Spring存储库实现没有错误,因此域层不受测试. 我对单元测试的一般知识是,在为服务层编写单元测试时,我需要模拟我的域层. 我假设域层不需要进行测试,事...

java – 为什么新的线程在事务Spring JUnit测试中看不到主线程准备的测试数据?【代码】

我用Spring-boot-test写了一个Junit测试,在一个测试方法中,我首先准备了一些应该保存到MySQL DB的测试数据,然后我调用了目标方法,应该在100个子线程中进行测试来测试目标方法是否在并发中运行良好.此测试方法如下所示:public class SysCodeRuleServiceImplTest extends BaseServiceTest {@Autowiredprivate SysCodeRuleService sysCodeRuleService;@Autowiredprivate SysCodeRuleDtlService sysCodeRuleDtlService;private final ...

Spring Web服务单元测试:java.lang.IllegalStateExcepton:无法加载应用程序上下文【代码】

当我尝试从Eclipse中运行我的单元测试时,我收到错误“java.lang.IllegalStateExcepton:无法加载应用程序上下文”. 单元测试本身看起来很简单:package com.mycompany.interactive.cs.isales.ispr.ws.productupgrade;import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUn...

java – 测试类应该存储在项目中的哪个位置?【代码】

我使用RAD / Eclipse在工作中构建我的所有Web项目,我很想知道您通常在哪里存储测试的* .class文件. 我的所有Web项目都有2个源文件夹:源代码为“src”,测试用例为“test”.两个源文件夹生成的* .class文件当前位于WebContent / WEB-INF / classes文件夹下. 我想从src * .class文件中分离测试* .class文件有两个原因: – >将它们存储在WebContent / WEB-INF / classes中并将它们部署到生产中是没有意义的.> Sonar和其他一些静态代...

java – 单元测试同步【代码】

请考虑以下方法:/*** Set whether messages are printed to System.out. * * @param printOutput True to print, false for silent logging*/ public void setPrintOutput(boolean printOutput) {// Synchronize to messages because this field is used when a message is receivedsynchronized (messages) {this.printOutput = printOutput;} }此方法是涉及消息的一组方法的一部分,因此我想编写一个测试,检查此方法是否在消...